Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Graphic for button in Free-Standing application  RSS feed

 
Kel Lin
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am writing a Free-Standing application using Java j2sdk1.4.1_04. The usual button that we create by just simply type the text on, can we place a picture/graphic instead of using text? Please advise the coding on how I can code it.
I have been searching over the book and net and couldnt find any.
 
Rob Ross
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, if you are going to do any serious Java development you need to become proficient in using the API JavaDocs. They have all the answers to these type of questions. There's an online version here, and you can also download it to your local machine.
The answer to your specific question is to use the setIcon() method of JButton, a Swing component (javax.swing.JButton.) This component will let you include a graphic on the button along with the text.
Finally, this is not an applet question so I am moving this topic to the Swing/AWT forum if you want to continue this dicussion.
Rob
[ August 25, 2003: Message edited by: Rob Ross ]
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can also pass the ImageIcon to the JButton constructor instead of using the setIcon method. One line less of code.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!