Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Anirban dutta
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 327
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Anirban dutta
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic