Here you can find the source of setIconImageFromResource(JFrame frame, String resource)
Parameter | Description |
---|---|
frame | The JFrame. |
resource | Path of the resource, i.e. "images/main.gif", relative to the class. |
public static void setIconImageFromResource(JFrame frame, String resource)
//package com.java2s; //License from project: Open Source License import java.awt.Image; import javax.swing.ImageIcon; import javax.swing.JFrame; public class Main { /**// w w w . j a v a2 s .co m * Set the icon image for a JFrame from a resource in its class. If the * image is null, it will set that, which should result in using the default * image. * * @param frame The JFrame. * @param resource Path of the resource, i.e. "images/main.gif", relative to * the class. */ public static void setIconImageFromResource(JFrame frame, String resource) { Image image = null; if (frame != null && resource != null) { image = getImageFromClassResource(frame.getClass(), resource); } frame.setIconImage(image); } /** * Get an Image from a resource in a class. * * @param cls The class. * @param resource Path of the resource, i.e. "images/main.gif", relative to * the class. * @return */ public static Image getImageFromClassResource(Class<?> cls, String resource) { if (cls == null || resource == null) return null; java.net.URL imgURL = cls.getResource(resource); if (imgURL != null) { return new ImageIcon(imgURL).getImage(); } else { return null; } } }