Here you can find the source of getTreeImage(String imageName)
Parameter | Description |
---|---|
imageName | the String representing the image to be returned |
public static ImageIcon getTreeImage(String imageName)
//package com.java2s; // The JavaPOS Config/Loader (aka JCL) is now under the CPL license, which import java.util.Vector; import java.io.*; import java.awt.Toolkit; import javax.swing.*; public class Main { public static final String PATHFORIMAGEFILES = "jpos/res/images/"; /** /*from ww w . j a v a 2 s .c o m*/ * @return an ImageIcon from anywhere in the classpath * @param imageName the String representing the image to be returned * @since 1.3 (SF 2K meeting) */ public static ImageIcon getTreeImage(String imageName) { String imageFileName = PATHFORIMAGEFILES + imageName; ImageIcon treeImageIcon = null; try { Vector v = new Vector(); InputStream is = ClassLoader.getSystemClassLoader() .getResourceAsStream(imageFileName); if (is == null) is = ClassLoader .getSystemResourceAsStream(PATHFORIMAGEFILES + "unknown.gif"); is = new BufferedInputStream(is); while (is.available() > 0) { byte[] buffer = new byte[is.available()]; is.read(buffer); v.addElement(buffer); } int size = 0; for (int i = 0; i < v.size(); ++i) { byte[] buffer = (byte[]) v.elementAt(i); size += buffer.length; } byte[] bigBuffer = new byte[size]; int dstPos = 0; for (int i = 0; i < v.size(); ++i) { byte[] buffer = (byte[]) v.elementAt(i); System.arraycopy(buffer, 0, bigBuffer, dstPos, buffer.length); dstPos += buffer.length; } treeImageIcon = new ImageIcon(Toolkit.getDefaultToolkit() .createImage(bigBuffer)); } catch (IOException ioe) { treeImageIcon = null; } return treeImageIcon; } }