Java - Resize ImageIcon

October 2016


I have a question about ImageIcon in Java:

I my application automatically creates images jpg, that can be of any size. And I would put the image created by a JLabel (specific size) in 400x400.
  • How to have the image displayed in full-size in JLabel?


ImageIcon icon = new ImageIcon("tonImage.jpg"); 
Image img = icon.getImage(); 
BufferedImage bi = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_ARGB); 
Graphics g = bi.createGraphics(); 
g.drawImage(img, 0, 0, WIDTH, HEIGHT, null); 
IconImage newIcon = new IconImage(bi); 

Thanks to Marc for this tip.

Related :

This document entitled « Java - Resize ImageIcon » from CCM ( is made available under the Creative Commons license. You can copy, modify copies of this page, under the conditions stipulated by the license, as this note appears clearly.