Java JDialog Icon setDialogIcon(JDialog dlg)

Here you can find the source of setDialogIcon(JDialog dlg)

Description

Set the Icon for an dialog

License

Open Source License

Parameter

Parameter Description
dlg the dialog

Declaration

static void setDialogIcon(JDialog dlg) 

Method Source Code


//package com.java2s;
/*//w ww.  j a v a 2s.  c o m
 *  JOrtho
 *
 *  Copyright (C) 2005-2008 by i-net software
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License as 
 *  published by the Free Software Foundation; either version 2 of the
 *  License, or (at your option) any later version. 
 *
 *  This program is distributed in the hope that it will be useful, but
 *  WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 *  General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 *  USA.
 *  
 *  Created on 10.11.2005
 */

import java.awt.Dialog;
import java.awt.Image;

import javax.imageio.ImageIO;

import javax.swing.JDialog;

public class Main {
    /**
     * Set the Icon for an dialog
     * @param dlg the dialog
     */
    static void setDialogIcon(JDialog dlg) {
        try {
            Image image = ImageIO.read(dlg.getClass().getResourceAsStream("icon.png"));
            // setIconImage appeared in Java 6.0 so use reflection to be compatible
            // with earlier JVMs. Equivalent to calling setIcomImage(image);
            Class cls = Dialog.class;
            java.lang.reflect.Method m = cls.getMethod("setIconImage", new Class[] { Image.class });
            m.invoke(dlg, new Object[] { image });
        } catch (Throwable e1) {
            // can occur in Java 5 or if the icon was removed, then use the default
        }
    }
}

Related

  1. jdialog$setIconImage(JDialog dlg, Image image)
  2. setDialogIcon(JDialog dialog, InputStream imageInputStream)
  3. setIconImage(JDialog j, Image b)
  4. setWindowIcon(JDialog jd)