0

I am writing a main menu for my Java Swing application, I want it to have 3 options: "New Game", "High Scores", "Exit" and a background image. I created a JPanel, for these 3 buttons and a JLabel with some title(i.e "Main Menu"). JLayeredPane seems to be the best choice for making a menu with a background image, so I decided to implement it, and this is where my problem comes up.

As I understood by reading the JLayeredPane docs, it can have only 1 Layout type. I imagined doing it by giving my JPanel - the one with buttons and a label - a GridBagLayout and giving my other JPanel with background image an absolute position. But how can I do it if giving an absolute position to an object requires having Layout set to null?

Thanks in advance!

olimpiabaku
  • 151
  • 11
  • 1
    *JLayeredPane seems to be the best choice for making a menu with a background image,* - See [Background Panel](https://tips4java.wordpress.com/2008/10/12/background-panel/) for a couple of other approaches. – camickr May 04 '21 at 02:00
  • 3
    Use a `JPanel` as the background container and render the image to it, for [example](https://stackoverflow.com/questions/26854010/ugly-swing-button-background/26855237#26855237), [example](https://stackoverflow.com/questions/22162398/how-to-set-a-background-picture-in-jpanel/22162430#22162430), [example](https://stackoverflow.com/questions/28889667/create-a-form-with-a-background-image-jlayeredpane/28889883#28889883), [example](https://stackoverflow.com/questions/24176008/background-image-for-a-jpanel-not-working/24176183#24176183) – MadProgrammer May 04 '21 at 02:00

0 Answers0