0

I have a class that extends JFrame, and I have decided to create an opening panel, a JPanel with 4 JButtonss which is added add(initPanel) in the constructor.

However, ideally a background image would help the JFrame look cleaner and decorated.

Someone on here suggested I use setContentPane(), and this in fact works.

However, the image appears and all the buttons/text disappear, and I can't get them to show.

I am wondering if there is any way to stack layers / JComponents within a JFrame, so I could have my image in the background and my JPanel in the foreground.

Jad Chahine
  • 6,849
  • 8
  • 37
  • 59
ajax992
  • 917
  • 9
  • 16
  • 1
    [A Visual Guide to Layout Managers](https://docs.oracle.com/javase/tutorial/uiswing/layout/visual.html) and [Simplest way to set image as JPanel background](http://stackoverflow.com/questions/19125707/simplest-way-to-set-image-as-jpanel-background) – Jonny Henly Apr 24 '16 at 09:43
  • For [example](http://stackoverflow.com/questions/22162398/how-to-set-a-background-picture-in-jpanel/22162430#22162430), [example](http://stackoverflow.com/questions/31526190/jframe-with-background-image-and-a-jpanel/31527567#31527567), [example](http://stackoverflow.com/questions/19631684/buttons-are-being-hidden-by-background-image/19632056#19632056) – MadProgrammer Apr 24 '16 at 10:18
  • *"I use "setContentPane()", and this in fact works. However, the image appears and all the buttons/text disappear*" - Make sure you call `setContentPane` BEFORE you try adding anything to the frame, also make sure you set the layout manager of the frame/content pane AFTER you've set it – MadProgrammer Apr 24 '16 at 10:19
  • *"so I could have my image in the background and my JPanel in the foreground."* - Also beware that `JPanel` is opaue by default – MadProgrammer Apr 24 '16 at 10:23

0 Answers0