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 resourcePath)
create Image Icon
return new ImageIcon(Thread.currentThread().getContextClassLoader().getResource(resourcePath));
ImageIconcreateImageIcon(URL url)
create Image Icon
return (url != null) ? new ImageIcon(url) : null;
ImageIconcreateImageIcon(URL url, String description, Integer w, Integer h)
create Image Icon
ImageIcon imageIcon = new ImageIcon(url, description);
if (w != null && h != null) {
    imageIcon = new ImageIcon(imageIcon.getImage().getScaledInstance(w, h, java.awt.Image.SCALE_SMOOTH));
return imageIcon;
JLabelcreateImageIconJLabel(ClassLoader classloader, String path, String description, String text)
create Image Icon J Label
ImageIcon icon = createImageIcon(classloader, path, description);
JLabel label = new JLabel(text, icon, JLabel.LEFT);
return label;
javax.swing.ImageIcon[]createImageIcons(java.awt.Image... images)
create Image Icons
javax.swing.ImageIcon[] rv = new javax.swing.ImageIcon[images.length];
int i = 0;
for (java.awt.Image image : images) {
    rv[i] = createImageIcon(image);
    i++;
return rv;
ImagegetIconImage(Icon icon)
get Icon Image
if (icon instanceof ImageIcon) {
    ImageIcon imageIcon = (ImageIcon) icon;
    return imageIcon.getImage();
} else {
    Image image = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2 = (Graphics2D) image.getGraphics();
    icon.paintIcon(null, g2, 0, 0);
    icon = new ImageIcon(image);
...
ImageIcongetIconImage(String path)
get Icon Image
URL url = System.class.getResource(path);
if (url == null) {
    System.err.println("Unable to load image: " + path);
ImageIcon icon = new ImageIcon(url);
return icon;
ImageIcontoImageIcon(File file, int width, int height)
to Image Icon
ImageIcon lImageIcon = null;
BufferedImage lBufferedImage = ImageIO.read(file);
if (lBufferedImage != null) {
    BufferedImage lBufferedImageResized = resizeImage(lBufferedImage, width, height);
    lImageIcon = new ImageIcon(lBufferedImageResized);
return lImageIcon;
ImageIcontoImageIcon(Icon icon)
Returns an ImageIcon based on a given Icon object.
if (icon instanceof ImageIcon) {
    return (ImageIcon) icon;
} else {
    return new ImageIcon(createImage(icon));
ImageIcontoImageIcon(URL resource, int width, int height)
to Image Icon
return new ImageIcon(getScaledImage(new ImageIcon(resource).getImage(), width, height));