Here you can find the source of stretchImage(ImageIcon image, int width, int height, ImageObserver imageObserver)
public static ImageIcon stretchImage(ImageIcon image, int width, int height, ImageObserver imageObserver)
//package com.java2s; //License from project: Open Source License import javax.swing.*; import java.awt.*; import java.awt.image.BufferedImage; import java.awt.image.ImageObserver; public class Main { public static ImageIcon stretchImage(ImageIcon image, int width, int height, ImageObserver imageObserver) { return stretchImage(image.getImage(), width, height, imageObserver); }/*from ww w . j a va 2 s. c om*/ public static ImageIcon stretchImage(Image image, int width, int height, ImageObserver imageObserver) { BufferedImage newImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D g = (Graphics2D) newImage.getGraphics(); g.drawImage(image, 0, 0, width, height, imageObserver); g.dispose(); return new ImageIcon(newImage); } }