Java Utililty Methods Swing Icon

List of utility methods to do Swing Icon

Description

The list of methods to do Swing Icon are organized into topic(s).

Method

IcongetDefaultIcon()
get Default Icon
BufferedImage bi = new BufferedImage(18, 18, BufferedImage.TYPE_INT_ARGB_PRE);
Graphics2D g2 = bi.createGraphics();
g2.setBackground(Color.red);
g2.clearRect(0, 0, bi.getWidth(), bi.getHeight());
g2.setColor(Color.white);
g2.setStroke(new BasicStroke(2));
GeneralPath x = new GeneralPath();
x.moveTo(0, 0);
...
ImageIcongetEmptyIcon()
Returns the ImageIcon for the empty icon.
return getIcon(EMPTY_ICON);
ImageIcongetFolderIcon()
get Folder Icon
return new ImageIcon("resources/images/folder.png");
IcongetFolderIcon()
Gets system default folder icon
Icon icon;
if (CACHE.containsKey("file-dir")) {
    icon = CACHE.get("file-dir");
} else {
    File temp = new File(System.getProperty("java.io.tmpdir") + File.separator + "icon");
    temp.mkdirs();
    icon = FileSystemView.getFileSystemView().getSystemIcon(temp);
    CACHE.put("file-dir", icon);
...
IcongetIcon(boolean isPressed, Icon baseIcon_)
get Icon
BufferedImage img = new BufferedImage(baseIcon_.getIconWidth(), baseIcon_.getIconHeight(),
        BufferedImage.TYPE_INT_ARGB);
Graphics g = img.getGraphics();
baseIcon_.paintIcon(TEMP, g, 0, 0);
g.dispose();
for (int i = 0; i < img.getWidth(); i++) {
    for (int j = 0; j < img.getHeight(); j++) {
        Color rgba = new Color(img.getRGB(i, j), true);
...
ImageIcongetIcon(Class baseclass, String name)
E.g.
try {
    return new ImageIcon(baseclass.getResource("images/" + name));
} catch (NullPointerException e) {
    e.printStackTrace();
    return null;
ImageIcongetIcon(Class clazz, String path)
get Icon
return (new ImageIcon(clazz.getResource(path)));
ImageIcongetIcon(final String path)
Create an icon from the resource at path.
return new ImageIcon(Thread.currentThread().getContextClassLoader().getResource(path));
ImageIcongetIcon(final String resource)
Load an icon for the given resource file.
URL url = Thread.currentThread().getContextClassLoader().getResource(resource);
if (url == null)
    return null;
return new ImageIcon(url);
IcongetIcon(int index)
This function returns the icon at a specific index
if (index >= 0 && index < icons.size()) {
    return icons.get(index);
return null;