Java ImageIcon createNonCachedImageIcon(File file)

Here you can find the source of createNonCachedImageIcon(File file)

Description

ImageIcon's constructors use MediaTracker to load an image, which is cached.

License

Open Source License

Declaration

public static ImageIcon createNonCachedImageIcon(File file) 

Method Source Code

//package com.java2s;
/*//from  w w  w.  ja va  2s  .  com
 *   Copyright (C) 2006  The Concord Consortium, Inc.,
 *   25 Love Lane, Concord, MA 01742
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the Free Software
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * END LICENSE */

import java.io.File;

import java.io.IOException;

import javax.imageio.ImageIO;

import javax.swing.ImageIcon;

public class Main {
    /**
     * ImageIcon's constructors use MediaTracker to load an image, which is cached. As a result, subsequent changes on
     * the content of the image do not show up. This method uses ImageIO class to remove the caching effect. Caution:
     * You should NOT use this method to create ImageIcon's whose content will NOT change.
     */
    public static ImageIcon createNonCachedImageIcon(File file) {
        try {
            return new ImageIcon(ImageIO.read(file));
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }
}

Related

  1. createCursor(ImageIcon icon, Point hotspot)
  2. createDisabledImage(final ImageIcon imageIcon)
  3. createEmptyImageIcon(final int width, final int height)
  4. createFileImageIcon(final String path)
  5. createMonoColoredImageIcon(final Paint paint, final int width, final int height)
  6. createOverlayIcon(Icon baseIcon, ImageIcon overlayIcon)
  7. createScaledImageIcon(byte[] albumArtBytes)
  8. CreateSizedImageIconScaledSmooth(URL filePath, int width, int height)
  9. createTempImage(ImageIcon icon, File oldFile)