Here you can find the source of getIcon(String name)
Synchronous; may not suitable for large images.
public static Icon getIcon(String name)
//package com.java2s; // Use is subject to license terms. import java.net.URL; import javax.swing.Icon; import javax.swing.ImageIcon; public class Main { private static ClassLoader classLoader = null; /******************************************************************** */*from w w w . j ava 2s .co m*/ * Gets a resource as an Icon.<p> * Synchronous; may not suitable for large images. * <p> * null if error * ********************************************************************/ public static Icon getIcon(String name) { URL url = getURL(name); if (url != null) { return new ImageIcon(url); } return null; } /******************************************************************** * * Given a resource name, extract a URL for the given resource. * ********************************************************************/ public static URL getURL(String name) { if (classLoader == null) { return null; } return classLoader.getResource(name); } }