Load an Icon from a jar (again)Tag(s): AWT


public static ImageIcon getImageIcon(String name) {
   return new ImageIcon(ClassLoader.getSystemResource(name));
   }

ImageIcon img = getImageIcon("resources/images/icone.gif");
Remember that it is always possible to the Java built-in icons so that you don't have to include your own standard icons.
public static Icon getIconForType(int iconType) {
    switch (iconType) {
        case 0:
            return UIManager.getIcon("OptionPane.errorIcon");
        case 1:
            return UIManager.getIcon("OptionPane.informationIcon");
        case 2:
            return UIManager.getIcon("OptionPane.warningIcon");
        case 3:
            return UIManager.getIcon("OptionPane.questionIcon");
    }
    return null;
}

A list of what icons are available can be found here
blog comments powered by Disqus