Java ImageIcon createFileImageIcon(final String path)

Here you can find the source of createFileImageIcon(final String path)

Description

create File Image Icon

License

Open Source License

Declaration

static ImageIcon createFileImageIcon(final String path) 

Method Source Code

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

import java.io.File;

import java.net.MalformedURLException;
import java.net.URL;

import javax.swing.ImageIcon;

public class Main {
    static ImageIcon createFileImageIcon(final String path) {
        try {/*from  w  ww  . j a  v  a2  s .  c  o  m*/
            ImageIcon imageIcon;
            File file;
            URL url;

            file = new File(path);

            if (!file.exists())
                throw new Error(String.format("Image \"%s\" not found.",
                        path));

            url = file.toURI().toURL();
            imageIcon = new ImageIcon(url);

            return imageIcon;
        } catch (MalformedURLException e) {
            throw new Error(e);
        }
    }
}

Related

  1. createColorImageIcon(int w, int h, int c)
  2. createCursor(ImageIcon cursorIcon, Point hotSpot, String name)
  3. createCursor(ImageIcon icon, Point hotspot)
  4. createDisabledImage(final ImageIcon imageIcon)
  5. createEmptyImageIcon(final int width, final int height)
  6. createMonoColoredImageIcon(final Paint paint, final int width, final int height)
  7. createNonCachedImageIcon(File file)
  8. createOverlayIcon(Icon baseIcon, ImageIcon overlayIcon)
  9. createScaledImageIcon(byte[] albumArtBytes)