I am trying to make a JLabel automatically resize when the JFrame resizes. I have tried doing what the answers on other threads have said, but all of them still appear the same. Whenever I maximize the window, the JLabel stays the same size and stays in the center. I am using GridBagLayout. I have also tried using a Thread to constantly update the size of the JLabel, but it didn't work. The JLabel holds an ImageIcon, and I think that the size of the image may be causing the JLabel to not resize. Any ideas?
EDIT: Here's my current code:
setLayout(new GridBagLayout());
GridBagConstraints gc=new GridBagConstraints();
gc.fill=GridBagConstraints.HORIZONTAL;
gc.gridx=0;
gc.gridy=0;
background=new JLabel(new ImageIcon(getClass().getResource("ingame.gif")));
add(background, gc);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
background.addMouseMotionListener(this);
And the JFrame looks like this:
https://i.stack.imgur.com/i8iJm.png
When the JLabel in the background is supposed to fill the entire JFrame.