-1

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.

javac
  • 2,431
  • 4
  • 17
  • 26
gtzinos
  • 1,205
  • 15
  • 27
  • Possible duplicate of [Java resize an image](http://stackoverflow.com/q/28701599/418556) or [Resizing image to fit frame](http://stackoverflow.com/q/10306335/418556) or [Resizing image to fit in JLabel](http://stackoverflow.com/q/22679717/418556) or.. – Andrew Thompson Apr 15 '15 at 09:01

1 Answers1

1

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);
gtzinos
  • 1,205
  • 15
  • 27