0

So for my project I just wanted the backgound to have a gif play to make it look nicer, but every solution I found wouldnt work. A solution where I make the gif on a JLabel then add everything onto the JLabel didnt work, the project ran but nothing showed up on screen. I have the gif called as this

 ImageIcon obj = new ImageIcon("assets/animate.gif");

My main looks like this

public static void main(String[] args0) {
    JFrame frame = new JFrame("inferdle");
    gamePanel window = new gamePanel();
    frame.add(window);
    frame.setSize(500,900);
    frame.setVisible(true);
    frame.setResizable(false);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

and I extend JPanel in the beggining. There are a bunch of box's that I add and those boxs have a bunch of JButtons

    hBox.add(sMenu);
    jBox.add(tMenu);
    add(hBox, BorderLayout.NORTH);
    add(jBox, BorderLayout.SOUTH);
    add(textBox, BorderLayout.EAST);

Is this even possible?

JMangoS
  • 11
  • 1
  • See: [Background Panel](https://tips4java.wordpress.com/2008/10/12/background-panel/). – camickr Mar 28 '22 at 16:48
  • A working implementation of an animated GIF being used as a background can be seen in [this answer](https://stackoverflow.com/a/10836833/418556). If you cannot adapt that successfully to your project, [edit] the question to add a [mre] as seen in that answer (ready to go as copy/pasted, hotlinking to the image). – Andrew Thompson Mar 29 '22 at 03:02

1 Answers1

0

It is definitely possible. You can use a JLayeredPane

Note though that there are questions you should be thinking with this: What happens if the JComponent is larger than your background? What if it's smaller? If you want to do tiling, you might want to look at the Paint class and Graphics2D.setPaint

ControlAltDel
  • 33,923
  • 10
  • 53
  • 80