Java Utililty Methods ImageIcon Create

List of utility methods to do ImageIcon Create

Description

The list of methods to do ImageIcon Create are organized into topic(s).

Method

ImageIconcreateImageIcon(String imgFile)
create image icon
URL imgUrl = ClassLoader.getSystemClassLoader().getResource(imgFile);
if (imgUrl == null) {
    return null;
return new ImageIcon(imgUrl);
ImageIconcreateImageIcon(String path)
Create an ImageIcon from the image at the specified path
URL u = Thread.currentThread().getContextClassLoader().getResource(path);
if (u == null) {
    return null;
return new ImageIcon(u);
ImageIconcreateImageIcon(String path)
Create an ImageIcon from the image at the specified path
URL u = Thread.currentThread().getContextClassLoader().getResource(path);
if (u == null)
    return null;
return new ImageIcon(u);
ImageIconcreateImageIcon(String path)
Creates an icon from an image path.
URL imgURL = null;
try {
    imgURL = new URL("file:" + path);
} catch (MalformedURLException e) {
    e.printStackTrace();
if (imgURL != null) {
    return new ImageIcon(imgURL);
...
ImageIconcreateImageIcon(String path)
create Image Icon
java.net.URL imgURL = ClassLoader.getSystemResource(path);
if (imgURL != null)
    return new ImageIcon(imgURL);
else
    throw new FileNotFoundException(path);
ImageIconcreateImageIcon(String path, Class resourceClass)
create Image Icon
java.net.URL imgURL = resourceClass.getResource(path);
if (imgURL != null) {
    return new ImageIcon(imgURL);
} else {
    System.err.println("Couldn't find file: " + path);
    return null;
ImageIconcreateImageIcon(String path, Class c)
Create an Image icon from the provided path.
URL imgURL = c.getResource(path);
if (imgURL != null) {
    return new ImageIcon(imgURL);
} else {
    return null;
ImageIconcreateImageIcon(String path, int width, int height)
create Image Icon
URL imgURL = ClassLoader.getSystemResource("img/" + path);
return new ImageIcon(
        new ImageIcon(imgURL).getImage().getScaledInstance(width, height, Image.SCALE_DEFAULT));
ImageIconcreateImageIcon(String path, String description)
Returns an ImageIcon, or null if the path was invalid.
return new ImageIcon(path, description);
ImageIconcreateImageIcon(String path, String description)
Returns an ImageIcon, or null if the path was invalid.
java.net.URL imgURL = Thread.currentThread().getContextClassLoader().getResource(path);
if (imgURL != null) {
    return new ImageIcon(imgURL, description);
} else {
    System.err.println("Couldn't find file: " + path);
    return null;