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; /*//from w w w.jav a 2s . c o m * Copyright (C) 2013 Maino * * This work is licensed under the Creative Commons * Attribution-NonCommercial-NoDerivs 3.0 Unported License. To view a copy of * this license, visit http://creativecommons.org/licenses/by-nc-nd/3.0/ or send * a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, * California, 94105, USA. * */ import java.awt.Graphics2D; import java.awt.Image; import java.awt.image.BufferedImage; import java.awt.image.ImageObserver; import javax.swing.ImageIcon; public class Main { public static ImageIcon stretchImage(ImageIcon image, int width, int height, ImageObserver imageObserver) { return stretchImage(image.getImage(), width, height, imageObserver); } 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); } }