Java ImageIcon Load getImageIcon(String name)

Here you can find the source of getImageIcon(String name)

Description

Get an ImageIcon.

License

Open Source License

Declaration

public static ImageIcon getImageIcon(String name) 

Method Source Code

//package com.java2s;
//  Use is subject to license terms.

import java.net.URL;

import javax.swing.ImageIcon;

public class Main {
    private static ClassLoader classLoader = null;

    /********************************************************************
     */*from ww w.ja v a  2 s . c  o m*/
     * Get an ImageIcon. Return null if an ImageIcon could not be found.
     *
     ********************************************************************/
    public static ImageIcon getImageIcon(String name) {
        URL url = getURL(name);
        if (url != null) {
            return new ImageIcon(url);
        }

        return null;
    }

    /********************************************************************
     *
     *   Given a resource name, extract a URL for the given resource.
     *
     ********************************************************************/
    public static URL getURL(String name) {
        if (classLoader == null) {
            return null;
        }

        return classLoader.getResource(name);
    }
}

Related

  1. getImageIcon(final String iconName)
  2. getImageIcon(final String location)
  3. getImageIcon(Image imp, int width, int height)
  4. getImageIcon(String filename)
  5. getImageIcon(String filename, String description)
  6. getImageIcon(String name)
  7. getImageIcon(String path)
  8. getImageIcon(String path, String description)
  9. getImageIcon(String res)