File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes How to place image on JButton Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Customer Requirements for Developers this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to place image on JButton" Watch "How to place image on JButton" New topic
Author

How to place image on JButton

Ashish Gundewad
Greenhorn

Joined: Oct 10, 2010
Posts: 14

Hello,
I want to place an image on JButton.
I am creating a object of ImageIcon and passing it to JButton like

JButton myJButton = new JButton("JButton", ImgObj);

The image is of .bmp format.
But i am not able to get image on the button.
Have I done any mistake.
Please help me.
Thanks..
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2361
    
    8
Not sure if .bmp files are supported. Try a .jpg or .gif.
Ashish Gundewad
Greenhorn

Joined: Oct 10, 2010
Posts: 14

Its working in .jpg format.
Thanks Rob.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to place image on JButton
 
It's not a secret anymore!