Win a copy of The Java Performance Companion this week in the Performance 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: 283
  • 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