[java] How to resize JLabel ImageIcon?

I'm making a Java Swing application that has the following layout (MigLayout):

[icon][icon][icon][....]
where icon = jlabel and the user can add more icons

When the user adds or removes icons, the others should shrink or grow.

My question is really straightforward: I have a JLabel which contains an ImageIcon; how can I resize this icon?

This question is related to java image swing

The answer is


Try this :

ImageIcon imageIcon = new ImageIcon("./img/imageName.png"); // load the image to a imageIcon
Image image = imageIcon.getImage(); // transform it 
Image newimg = image.getScaledInstance(120, 120,  java.awt.Image.SCALE_SMOOTH); // scale it the smooth way  
imageIcon = new ImageIcon(newimg);  // transform it back

(found it here)


Similar questions with java tag:

Similar questions with image tag:

Similar questions with swing tag: