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?
CodePudding user response:
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
CodePudding user response:
This question has been already answered here How to set Icon to JFrame