Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

setting image as a background

 
Jennifer Sohl
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible to set the background of a JPanel with an ImageIcon?
I have a JPanel that I want to put a JPEG on, as well as two JButtons. But I can't seem to find a way to put the buttons on top of the image.
I thought this may be a possibility? If not, could someone please give me some other ideas?
Thanks!
 
Greg Charles
Sheriff
Posts: 3010
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm sure you'll get a better answer through here, but what I would do is:
1. Set your image onto a JPanel (jpanel1)
2. Set layout of jpanel1 to BorderLayout.
3. Add another JPanel (jpanel2) to the center of jpanel1.
4. jpanel2.setOpaque(false);
5. Add buttons or whatever to jpanel2.
If you add other panels to jpanel2, make sure to setOpaque to false on them as well.
 
Die Fledermaus does not fear such a tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!