Java JDialog Icon setWindowIcon(JDialog jd)

Here you can find the source of setWindowIcon(JDialog jd)

Description

set Window Icon

License

Apache License

Declaration

public static void setWindowIcon(JDialog jd) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import javax.swing.*;

import java.awt.*;

import java.awt.image.*;

public class Main {
    private static ImageIcon gDefaultFrameIcon;

    public static void setWindowIcon(JDialog jd) {
        ImageIcon frameIcon = getDefaultFrameIcon();
        if (frameIcon != null)
            jd.setIconImage(frameIcon.getImage());
    }/*from   w  w  w  .  jav  a 2  s . co m*/

    public static void setWindowIcon(JFrame jd) {
        ImageIcon frameIcon = getDefaultFrameIcon();
        if (frameIcon != null)
            jd.setIconImage(frameIcon.getImage());
    }

    public static ImageIcon getDefaultFrameIcon() {
        return gDefaultFrameIcon;
    }

    /**
     * draw the component as an image
     *
     * @param component
     * @return
     */
    public static BufferedImage getImage(JComponent component) {
        BufferedImage ret = new BufferedImage(component.getWidth(), component.getHeight(),
                BufferedImage.TYPE_INT_RGB);
        Graphics g = ret.getGraphics();
        component.paint(g);
        g.dispose();
        return ret;
    }
}

Related

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