Java Swing Icon getIcon(String name, ClassLoader classLoader)

Here you can find the source of getIcon(String name, ClassLoader classLoader)

Description

get Icon

License

Open Source License

Declaration

public static Icon getIcon(String name, ClassLoader classLoader) 

Method Source Code


//package com.java2s;
import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import javax.swing.Icon;
import javax.swing.ImageIcon;

public class Main {
    public static Icon getIcon(String name, ClassLoader classLoader) {

        BufferedInputStream iconIn;
        ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
        int i;//from   w  ww  .  ja  va2  s  .c  o m

        iconIn = new BufferedInputStream(classLoader.getResourceAsStream(name));
        try {
            while ((i = iconIn.read()) > -1) {
                byteOut.write(i);
            }
            return new ImageIcon(byteOut.toByteArray());
        } catch (IOException e) {
            return null;
        }
    }
}

Related

  1. getIcon(String name)
  2. getIcon(String name)
  3. getIcon(String name)
  4. getIcon(String name)
  5. getIcon(String name, boolean isGrayIcon)
  6. getIconCheckBox(String iconPath, String pressIconPath, String rolloverIconPath, String selectedIconPath)
  7. getIconFromExtension(String f, boolean folder)
  8. getIconInterTrial()
  9. getIcono()