Here you can find the source of getImageIcon(String filename, String description)
Parameter | Description |
---|---|
filename | Image filename (relative to IMAGE_DIR) to get |
description | String description of icon, or null |
public static ImageIcon getImageIcon(String filename, String description)
//package com.java2s; //License from project: BSD License import java.util.ResourceBundle; import javax.swing.ImageIcon; public class Main { /**/*from w w w . ja v a2s.c o m*/ * Same as getImageIcon(String, String) with null description. Uses soft * references to avoid creating more than one copy of the same image, and * help with memory management. * * @see #getImageIcon(String, String) * @param filename * Image filename (relative to IMAGE_DIR) to get * @return ImageIcon for that filename, or null if no file exists */ public static ImageIcon getImageIcon(String filename) { return getImageIcon(filename, null); } /** * Keeps a hashmap of SoftReferences to images, hashed by filename, so that * the same image icon will be used for multiple versions of the same image. * The SoftReferences ensure that if the images are no longer directly * reachable, they will be garbage collected before an OutOfMemoryError is * thrown. * * @deprecated Use ImageBundle instead... * * @param filename * Image filename (relative to IMAGE_DIR) to get * @param description * String description of icon, or null * @return */ public static ImageIcon getImageIcon(String filename, String description) { ResourceBundle bundle = ResourceBundle.getBundle("com.stottlerhenke.simbionic.editor.gui.ImageBundle"); try { ImageIcon icon = (ImageIcon) bundle.getObject(filename); if (icon == null) return new ImageIcon(); return icon; } catch (Exception e) { return new ImageIcon(); } // File f = new File("images" + filename); // // System.gc(); // if (softImages.containsKey(f)) { // SoftReference sr = (SoftReference) softImages.get(f); // ImageIcon icon = (ImageIcon) sr.get(); // if (icon != null) // return icon; // } // ImageIcon icon; // if (f.exists()) { // if (description != null) // icon = new ImageIcon(f.toString(), description); // else // icon = new ImageIcon(f.toString()); // softImages.put(f, new SoftReference(icon)); // return icon; // } // return null; } }