Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9157125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:56:13+00:00 2026-06-17T12:56:13+00:00

I am coding an image puzzle game and one part of the code is

  • 0

I am coding an image puzzle game and one part of the code is to compare the pieces the user has selected to the pieces of the correct image.

Each image piece is already added to a JButton as an ImageIcon.

An identifier is required to differentiate each image piece apart and also for comparision.

I am setting a setText() for each JButton created as the identifier.

But doing so will cause both the ImageIcon and setText to show up on the JButton.

Is there a way to hide the setText value and only display the ImageIcon ?

        private String id;
        private int cc;
        private JButton[] button = new JButton[9];

        cc += 1;
        id += ""+cc;

        for(int a=0; a<9; a++){
            // dd refers to the variable for the image pieces for each JButton
        button[a].setIcon(new ImageIcon( dd ));
        button[a].setText(id);
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T12:56:14+00:00Added an answer on June 17, 2026 at 12:56 pm

    I recommend making another array of Strings:

    String[] ids = new String[button.length];
    

    And then button[a]‘s ID would be ids[a].

    Here is your code with the change:

        private String id;
        private int cc;
        private JButton[] button = new JButton[9];
        private String[] ids = new String[button.length];
    
        //cc += 1;
        //id += ""+cc;
        id += Integer.toString(++cc); //easier way
    
        for(int a=0; a<9; a++){
            // dd refers to the variable for the image pieces for each JButton
            button[a].setIcon(new ImageIcon( dd ));
            ids[a] = id;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am coding an image puzzle game and one part of the code is
I'm coding a Qt 4.8 program ( http://code.google.com/p/image-feature-detector/ ) with NetBeans 7.1 in Kubuntu
I was coding a snake game, and i got an apple image to use
I am doing a image processing project(small one). I am coding algorithms in matlab
i have following coding to resize image and than save it my virtual folder
I have this peice of coding which simply swaps an image when a link
i m really very fed up coding translate animation. actually my image is moving
I'm coding in c++, and I'm trying to load an image file asynchronously. After
I am coding a galery in jquery. I have an image zoom tool that
There's this image on a page I'm coding which should be resized and horizontally

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.