I'm relatively new to Java, so I'm not even sure if this is possible, but I need to somehow get my JLabel to dynamically resize with my JFrame. It might be something as simple as a single line of code I'm missing, but frankly, I don't have the experience needed to solve this for myself.
I tried googling and browsing through other Stack posts, but they were either generally unhelpful or tried to get me to do something like
class ImagePanel extends JPanel
or something along those lines --> which I can't do because I'm already extending my code with something else.
Hopefully I'm phrasing my question correctly as well...
Just in case, to clarify, I need my image to automatically resize itself as I resize the frame around it.
My code is below:
public static void ScalingImage() throws IOException
{
MyCollage GP = new MyCollage();
BufferedImage image = ImageIO.read(new File("myCollage_Final.jpg"));
JLabel label = new JLabel(new ImageIcon(image));
JFrame aFrame = new JFrame();
int picwidth = (int)Math.round(aFrame.getWidth());
int picheight = (int)Math.round(aFrame.getHeight());
aFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
aFrame.getContentPane().add(label);
aFrame.pack();
aFrame.setSize(2000, 2000);
aFrame.add(GP);
aFrame.setLocation(0, 0);
aFrame.setVisible(true);
}
So, if it's something obvious I'm missing, I'd love to know what it is. And if it's something not-so-obvious, then... I'd still love to know what it is haha.