Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

access the sources of the JButtons with no labels but Icons

 
Philip Joshua Gaje
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java.lang.Sample [size=12]
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How would you do it if the buttons had
labels (text?) and no icons?

or both?
 
Philip Joshua Gaje
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if the button had a label, I often use event.getSource() to access that button. I just don't know what to use if both label and icon are not in the button, and specifically i only used a button with icon but without label.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what does event.getSource() return?
 
Randall Twede
Ranch Hand
Posts: 4390
3
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the link is not working. e.getSource() returns the name of the member variable that caused the event(i'm pretty sure). i like it better with text on my button. i can then say e.getSource().getText(). or better yet i can use e.getActionComand()
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> e.getSource() returns the name of the member variable that caused the event

the question was directed at the OP, to get him to think about what he's doing
i.e. if he can access the button when it has text, why can't he access it with no text
 
Manuel Petermann
Ranch Hand
Posts: 177
Hibernate Linux Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
e.getSource().getText() is not the same as e.getActionComand(). Former gets the text of the button and later gets the string used for the command. Both are not necessarily the same.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic