Here you can find the source of getResourceIcon(Object target, String name)
Parameter | Description |
---|---|
target | - Object holding resource |
name | the file name |
public static Icon getResourceIcon(Object target, String name)
//package com.java2s; //License from project: Apache License import java.awt.*; import java.io.*; import javax.swing.*; public class Main { /**/*from w w w. j a v a 2 s.co m*/ * { method * * @param target - Object holding resource * @param name the file name * @return Icon for the resource possibly null * } * @name getResourceIcon * @function read an Icon as a Resource */ public static Icon getResourceIcon(Object target, String name) { return (getResourceIcon(target.getClass(), name)); } /** * { method * * @param target - Class holding resource * @param name the file name * @return Icon for the resource possibly null * } * @name getResourceIcon * @function read an Icon as a Resource */ public static Icon getResourceIcon(Class target, String name) { try { // Netscape appears not to support getResource so this // reads an image from a resource // InputStream is = target.getResourceAsStream(name); if (is == null) { System.err.println("Resource not found. " + name + " as Reference in class " + target.getName()); return (null); } ByteArrayOutputStream baos = new ByteArrayOutputStream(); int c; while ((c = is.read()) >= 0) baos.write(c); is.close(); Image TheActualImage = Toolkit.getDefaultToolkit().createImage(baos.toByteArray()); Icon TheImage = new ImageIcon(TheActualImage); return (TheImage); } catch (IOException e) { return (null); } catch (Exception ex) { // return(SecurityUtilities.secureGetResourceIcon(target,name) ); return (null); } } }