Java JFrame Icon getResourceIcon(JFrame fr, String name, Class callingClass)

Here you can find the source of getResourceIcon(JFrame fr, String name, Class callingClass)

Description

Set a icon for given frame CallingClass is used to determine where to find resource...

License

Open Source License

Declaration

public static void getResourceIcon(JFrame fr, String name, Class callingClass) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import javax.swing.*;

public class Main {
    /**/*from   ww  w . j av  a  2 s .c o m*/
     * Set a icon for given frame
     * CallingClass is used to determine where to find resource...
     */
    public static void getResourceIcon(JFrame fr, String name, Class callingClass) {
        try {
            ImageIcon i = null;
            i = new ImageIcon(callingClass.getResource(name));
            fr.setIconImage(i.getImage());
        } catch (Exception e) {
            System.out.println("Icon not loaded: " + name);
        }
    }

    /**
     * Set a icon for given frame
     * CallingClass is used to determine where to find resource...
     */
    public static void getResourceIcon(JInternalFrame fr, String name, Class callingClass) {
        try {
            ImageIcon i = null;
            i = new ImageIcon(callingClass.getResource(name));
            fr.setFrameIcon(i);
        } catch (Exception e) {
            System.out.println("Icon not loaded: " + name);
        }
    }
}

Related

  1. loadIMageIconToPanel(JFrame frame, JPanel panel, ImageIcon icon)
  2. SET_FRAME_ICON(JFrame f, String iconPath)
  3. setApplicationIcon(JFrame frame)
  4. setDefaultIcon(final JFrame window, final String imagepath)