Java ImageIcon Create createImageIcon(String path)

Here you can find the source of createImageIcon(String path)

Description

Create an ImageIcon from the image at the specified path

License

Open Source License

Parameter

Parameter Description
path The path of the image

Return

The image icon, or null if the image doesn't exist

Declaration

public static ImageIcon createImageIcon(String path) 

Method Source Code

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

import java.net.URL;

import javax.swing.ImageIcon;

public class Main {
    /**//  w ww . j  a  v a 2  s.  c  o  m
     * Create an ImageIcon from the image at the specified path
     *
     * @param path The path of the image
     * @return The image icon, or null if the image doesn't exist
     */
    public static ImageIcon createImageIcon(String path) {

        URL u = Thread.currentThread().getContextClassLoader().getResource(path);
        //URL u = ClassLoader.getSystemResource(path);//UIUtils.class.getResource(path);
        if (u == null) {
            return null;
        }
        return new ImageIcon(u);
    }
}

Related

  1. createImageIcon(final Icon icon)
  2. createImageIcon(final String src)
  3. createImageIcon(java.net.URL imgURL)
  4. createImageIcon(String iconFile)
  5. createImageIcon(String imgFile)
  6. createImageIcon(String path)
  7. createImageIcon(String path)
  8. createImageIcon(String path)
  9. createImageIcon(String path, Class resourceClass)