• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Graphic for button in Free-Standing application

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic