Here you can find the source of loadIcon(ClassLoader classLoader, String path)
public static ImageIcon loadIcon(ClassLoader classLoader, String path)
//package com.java2s; //License from project: Open Source License import java.awt.image.BufferedImage; import java.io.IOException; import java.net.URL; import javax.imageio.ImageIO; import javax.swing.ImageIcon; public class Main { public static ImageIcon loadIcon(String path) { BufferedImage image = loadImage(path); return (image != null) ? new ImageIcon(image) : null; }//from w w w . j a va 2s . c o m public static ImageIcon loadIcon(ClassLoader classLoader, String path) { BufferedImage image = loadImage(classLoader, path); return (image != null) ? new ImageIcon(image) : null; } public static BufferedImage loadImage(String path) { try { URL url = ClassLoader.getSystemResource(path); if (url != null) { return ImageIO.read(url); } else { return null; } } catch (IOException e) { throw new RuntimeException("I/O error loading image " + path, e); } } public static BufferedImage loadImage(ClassLoader classLoader, String path) { try { URL url = classLoader.getResource(path); if (url != null) { return ImageIO.read(url); } else { return null; } } catch (IOException e) { throw new RuntimeException("I/O error loading image " + path, e); } } }