Here you can find the source of getImageIcon(URL url)
public static ImageIcon getImageIcon(URL url)
//package com.java2s; // Licensed under the Apache License, Version 2.0 (the "License"); import javax.swing.*; import java.net.URL; public class Main { public static ImageIcon getImageIcon(String fileName) { URL url = ClassLoader.getSystemResource(fileName); return getImageIcon(url); }//from w w w . j av a2 s . c o m public static ImageIcon getImageIcon(URL url) { ImageIcon icon = (url == null) ? null : (new ImageIcon(url)); return icon; } public static ImageIcon getImageIcon(Object obj, String filePath) { URL url = obj.getClass().getResource(filePath); return getImageIcon(url); } }