Java ImageIcon Create getIconImage(String path)

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

Description

get Icon Image

License

Creative Commons License

Declaration

public static ImageIcon getIconImage(String path) 

Method Source Code

//package com.java2s;
/**/*w ww . ja  v  a  2  s  . co  m*/
 * Copyright 2013 by PanicLauncher and Contributors
 *
 * This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License.
 * To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/.
 */

import java.io.File;

import java.net.URL;

import javax.swing.ImageIcon;

public class Main {
    public static ImageIcon getIconImage(String path) {
        URL url = System.class.getResource(path);

        if (url == null) {
            System.err.println("Unable to load image: " + path);
        }

        ImageIcon icon = new ImageIcon(url);

        return icon;
    }

    public static ImageIcon getIconImage(File file) {
        if (!file.exists()) {
            System.err.println("Unable to load image: " + file.getAbsolutePath());
        }

        ImageIcon icon = new ImageIcon(file.getAbsolutePath());

        return icon;
    }
}

Related

  1. createImageIcon(URL url)
  2. createImageIcon(URL url, String description, Integer w, Integer h)
  3. createImageIconJLabel(ClassLoader classloader, String path, String description, String text)
  4. createImageIcons(java.awt.Image... images)
  5. getIconImage(Icon icon)
  6. toImageIcon(File file, int width, int height)
  7. toImageIcon(Icon icon)
  8. toImageIcon(URL resource, int width, int height)