import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.Point; import java.awt.Toolkit; import java.awt.geom.AffineTransform; import java.awt.image.AffineTransformOp; import java.awt.image.BufferedImage; import java.io.IOException; import javax.imageio.ImageIO; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JLabel; public class ResizeImageFrame extends JFrame { public ResizeImageFrame() throws IOException { setTitle("Resize image"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLayout(new FlowLayout()); JLabel img1 = new JLabel(); img1.setIcon(new ImageIcon(getClass().getResource("/arrow_right.png"))); add(img1); BufferedImage icon2 = ImageIO.read(getClass().getResource("/arrow_right.png")); // resize image AffineTransform transform = AffineTransform.getScaleInstance(30.0 / icon2.getWidth(), 30.0 / icon2.getHeight()); AffineTransformOp op = new AffineTransformOp(transform, AffineTransformOp.TYPE_BILINEAR); icon2 = op.filter(icon2, null); JLabel img2 = new JLabel(); img2.setIcon(new ImageIcon(icon2)); add(img2); pack(); Dimension sc = Toolkit.getDefaultToolkit().getScreenSize(); setLocation(new Point((sc.width - getWidth()) / 2, (sc.height - getHeight()) / 2)); setVisible(true); } /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { // TODO Auto-generated method stub new ResizeImageFrame(); } }