Here you can find the source of createImageIcon(String path, String description)
Parameter | Description |
---|---|
path | Relative path to image (from ClassLoader's original class location) (e.g. "images/image1.png") |
description | Image description |
public static ImageIcon createImageIcon(String path, String description)
//package com.java2s; //License from project: Open Source License import javax.swing.*; public class Main { /**//from w w w.j av a2 s .co m * Returns an ImageIcon, or null if the path was invalid. * * @param path Relative path to image (from ClassLoader's original class location) (e.g. "images/image1.png") * @param description Image description * @return Icon based on image file in path */ public static ImageIcon createImageIcon(String path, String description) { 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; } } }