Here you can find the source of loadImageIcon(Class clas, String iconPath)
Parameter | Description |
---|---|
clas | A class used to resolve the icon's relative path name |
iconPath | the path relative to the clas in which to find the icon. |
for a directory structure like edu/ mypackage/ MyClass.class images/ myicon.gif call loadImageIcon(MyClass.class, "images/myicon.gif");
public static ImageIcon loadImageIcon(Class clas, String iconPath)
//package com.java2s; import java.net.URL; import javax.swing.ImageIcon; public class Main { /**//w ww . j a v a2 s . c o m * Loads a icon from either the file system or from a jar. * * @param clas A class used to resolve the icon's relative path name * @param iconPath the path relative to the clas in which to find the icon. * @return an image icon for the icon, or null if not found * * <pre> * for a directory structure like * edu/ * mypackage/ * MyClass.class * images/ * myicon.gif * * call loadImageIcon(MyClass.class, "images/myicon.gif"); * * </pre> */ public static ImageIcon loadImageIcon(Class clas, String iconPath) { ImageIcon icon = null; URL url = clas.getResource(iconPath); if (url != null) { icon = new ImageIcon(url); } return icon; } }