Here you can find the source of getIcon(String name, ClassLoader classLoader)
public static Icon getIcon(String name, ClassLoader classLoader)
//package com.java2s; import java.io.BufferedInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import javax.swing.Icon; import javax.swing.ImageIcon; public class Main { public static Icon getIcon(String name, ClassLoader classLoader) { BufferedInputStream iconIn; ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); int i;//from w ww . ja va2 s .c o m iconIn = new BufferedInputStream(classLoader.getResourceAsStream(name)); try { while ((i = iconIn.read()) > -1) { byteOut.write(i); } return new ImageIcon(byteOut.toByteArray()); } catch (IOException e) { return null; } } }