This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

label and icon on JButton

 
Mindy Wu
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,
I have an array of buttons and each button has an icon image. I need to keep track of which button being clicked by the user. For example, if user click button[1], the event.getActionCommand() return 1. However, button[1] only has an icon, there is no label on the button, it is obvious there is nothing return.
My questions
1. how to get the icon name of the selected button
2. how to make an invisible label
my code:
for (count=1; count <=14; count++)
{
btn[count] = new JButton( rmIcon );
btn[count].setPreferredSize(new Dimension(40, 25));
btn[count].addActionListener(handler);
roomPanel.add(btn[count]);
}
How can i make the index invisible if i add the index on the button.
for (count=1; count <=14; count++)
{
btn[count] = new JButton( Integer.toString(count), rmIcon );
btn[count].setPreferredSize(new Dimension(40, 25));
btn[count].addActionListener(handler);
roomPanel.add(btn[count]);
}
Thank you!

[ March 16, 2004: Message edited by: Mindy Wu ]
 
Eddie Vanda
Ranch Hand
Posts: 281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use setActionCommand:
 
Mindy Wu
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Eddie,
Your help is greatly appreciated!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic