Could someone explain why this line of code isn’t working. No errors are given. It simply doesn’t resize the image.
image = ImageIO.read(file);
image.getScaledInstance(ImageDisplayBox.getWidth(), ImageDisplayBox.getHeight());
ImageDisplayBox.setIcon(new ImageIcon(image));
I’ve looked at the other answers on Stackoverflow and noticed a lot of people using the .getScaledInstance method.
I (think) it might be the fact that I have it as .setIcon – Although I’m not the best with Java.
The image is printed but displays only the top left of the image due to size.
You’re ignoring the returned value. You want:
Or maybe to make things clearer:
From the docs:
Note that that doesn’t say anything about changing the existing image. It just creates a new image with the given size.