Search code examples
javaswingjlabelimageicon

Show a big image in a smaller label Java Swing


I have this Java Swing code :

ImageIcon img;
img = new ImageIcon("./pictures/icon2.jpg");
label1.setIcon(img);

I change the size of the label but I need a very big label to show a big image. Cause I need to show more images with different sizes in the same label I need to show the full image in a smaller than image size label.


Solution

  • It works fine now.

    File file = new File("./pictures/icon2.jpg");
    BufferedImage bimg = ImageIO.read(file);
    Image scaled = bimg.getScaledInstance(500, 500, Image.SCALE_SMOOTH); 
    ImageIcon icon = new ImageIcon(scaled);
    photo_result.setIcon(icon);