wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes label and icon  on JButton Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "label and icon  on JButton" Watch "label and icon  on JButton" New topic
Author

label and icon on JButton

Mindy Wu
Ranch Hand

Joined: Jan 12, 2001
Posts: 121
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

Joined: Mar 18, 2003
Posts: 281
Use setActionCommand:


The nice thing about Standards is that there are so many to choose from!
Mindy Wu
Ranch Hand

Joined: Jan 12, 2001
Posts: 121
Hello Eddie,
Your help is greatly appreciated!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: label and icon on JButton
 
Similar Threads
Calling the repaint() method
A calculator question!
Setting Component Size
Won't repaint!
running a class a particular number of times