• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

label and icon on JButton

 
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use setActionCommand:
 
Mindy Wu
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Eddie,
Your help is greatly appreciated!
 
a wee bit from the empire
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic