A few words of thanks would be greatly appreciated.

Java - Resize ImageIcon


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.

A few words of thanks would be greatly appreciated.

Ask a question
Jean-François Pillou

CCM is a leading international tech website. Our content is written in collaboration with IT experts, under the direction of Jeff Pillou, founder of CCM.net. CCM reaches more than 50 million unique visitors per month and is available in 11 languages.

Learn more about the CCM team


Published by . Latest update on by aakai1056.

This document, titled "Java - Resize ImageIcon," is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (https://ccm.net/).