aspose file tools*
The moose likes Java in General and the fly likes [URGENT]Displaying an Image as an background of a JPanel Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "[URGENT]Displaying an Image as an background of a JPanel" Watch "[URGENT]Displaying an Image as an background of a JPanel" New topic
Author

[URGENT]Displaying an Image as an background of a JPanel

Anirban dutta
Ranch Hand

Joined: Aug 08, 2002
Posts: 89
Dear all,
I want to apply a image to the background of a JPanel. The JPanel is having 5 Buttons on it arranged vertically in a null layout. I tried applying a image to it by using g.drawImage in the paintComponent. It drew the image but the image was not properly distorted. It was not displayed in parts where there was a button on the JPanel. Can anybody please tell me how to display an image properly behind the buttons on a JPanel. Please this is URGENT.
Thanks
leo donahue
Ranch Hand

Joined: Apr 17, 2003
Posts: 327
Hi Anirban,
I may be wrong, but I couldn't find any methods in the java docs that set the background of a JPanel to a graphic image, inherited methods or otherwise.
I did find methods which let you add a graphic image to either a JLabel,(a Swing component) or a JFrame, (an awt component). Would either of these work for you?


Thanks, leo
Anirban dutta
Ranch Hand

Joined: Aug 08, 2002
Posts: 89
Dear Leo,
Thanks for your reply, but that will not work, as we cannot add any components to the frame or JLabel directly.
Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1134

Anirban,
In case you are unaware, there is an entry in the JFC Swing FAQ entitled How do I use an image as the background for a JPanel? that may be of help -- although it didn't work for me when I tried it.
Hope it helps.
Good Luck,
Avi.
JS Shirah
Greenhorn

Joined: Jan 23, 2003
Posts: 3
Take a look at my brief article "Displaying Background Images with Swing" at
http://www.conceptgo.com/articles/DisplayBackground.html
off conceptGO's community page. I think it will give you the information you need, although I'm a little confused by your statement "It was not displayed in parts where there was a button on the JPanel."

Joe Sam
Joe Sam Shirah — http://www.conceptgo.com
conceptGO — Consulting/Development/Outsourcing
Java Filter Forum: http://www.ibm.com/developerworks/java/
Just the JDBC FAQs: http://www.jguru.com/faq/JDBC
Going International? http://www.jguru.com/faq/I18N
Que Java400? http://www.jguru.com/faq/Java400
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: [URGENT]Displaying an Image as an background of a JPanel