Java Swing Icon loadIcon(ClassLoader classLoader, String path)

Here you can find the source of loadIcon(ClassLoader classLoader, String path)

Description

load Icon

License

Open Source License

Declaration

public static ImageIcon loadIcon(ClassLoader classLoader, String path) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URL;
import javax.imageio.ImageIO;

import javax.swing.ImageIcon;

public class Main {
    public static ImageIcon loadIcon(String path) {
        BufferedImage image = loadImage(path);
        return (image != null) ? new ImageIcon(image) : null;
    }//from   w  w  w  .  j  a  va 2s  .  c o m

    public static ImageIcon loadIcon(ClassLoader classLoader, String path) {
        BufferedImage image = loadImage(classLoader, path);
        return (image != null) ? new ImageIcon(image) : null;
    }

    public static BufferedImage loadImage(String path) {
        try {
            URL url = ClassLoader.getSystemResource(path);
            if (url != null) {
                return ImageIO.read(url);
            } else {
                return null;
            }
        } catch (IOException e) {
            throw new RuntimeException("I/O error loading image " + path, e);
        }
    }

    public static BufferedImage loadImage(ClassLoader classLoader, String path) {
        try {
            URL url = classLoader.getResource(path);
            if (url != null) {
                return ImageIO.read(url);
            } else {
                return null;
            }
        } catch (IOException e) {
            throw new RuntimeException("I/O error loading image " + path, e);
        }
    }
}

Related

  1. getVerBumpIcon()
  2. grayIcon(Icon icon)
  3. iconFromStream(final InputStream in)
  4. item(String name, Icon icon)
  5. loadIcon(Class pRootClass, String strPath)
  6. loadIcon(String icon)
  7. loadIcon(String resourceName)
  8. loadIcons(String list, String path, Set ignore, ClassLoader loader)
  9. loadLoadingIcon()