-1

I am currently building a game and I don't know how to make a main menu. I don't know how to put the text on the GIF background. Now the thing is when I try to put them on I try this code:

private void initializeDisplay() {
    playBtn.setBorderPainted(false);
    playBtn.setFocusPainted(false);
    playBtn.setContentAreaFilled(false);
    playBtn.setText("PLAY");
    playBtn.setFont(new Font("Poiret One", Font.TRUETYPE_FONT, 27));
    playBtn.setForeground(Color.WHITE);

    mainPanel.add(playBtn);
    mainPanel.add(bgImg);

    mainPanel.setLayout(new GridBagLayout());

    bgImg.setLocation(new Point(200, 200));

    mainPanel.setOpaque(true);
    mainPanel.addKeyListener(new Keyboard());
    mainPanel.addMouseListener(new Mouse());
    mainPanel.setFocusable(true);
}

Also when I do that I use a GridBagLayout for the layout type but it seems that I'm not get the result I want, the problem is the button not the image in the background because that's appearing but the button isn't appearing.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
zin
  • 415
  • 2
  • 5
  • 11
  • It would be nice if you can post an image! – Paulo Pedroso Apr 08 '16 at 23:20
  • You can use `JLayeredPane` to place components on top of each other. You can find more details here https://docs.oracle.com/javase/tutorial/uiswing/components/layeredpane.html – Titus Apr 08 '16 at 23:23
  • Thanks Titus, and also Paulo Pedroso its fullscreen and my screen is not compatible with the display so i cant take screen shots yet until i make them compatible – zin Apr 08 '16 at 23:25

1 Answers1

0

You could also add an image to a jlabel's icon field, and then add the label to your panel's content pane.

This post explains it more:

How to set a background picture in JPanel

Community
  • 1
  • 1
S. Cassidy
  • 61
  • 1
  • 5