creates an image icon from the file located at the specified path - Java 2D Graphics

Java examples for 2D Graphics:Image File

Description

creates an image icon from the file located at the specified path

Demo Code


import javax.swing.ImageIcon;

public class Main{
    /**//from   w ww. j  ava2  s  .c  o m
     * creates an image icon from the file located at the specified path
     */
    public static ImageIcon createImageIcon(String path, String description) {
        java.net.URL imgURL = DesktopUtils.class.getResource(path);
        if (imgURL != null) {
            return new ImageIcon(imgURL, description);
        } else {
            System.err.println("Couldn't find file: " + path);
            return null;
        }
    }
}

Related Tutorials