Java JFrame Icon setWindowIcon(JFrame jd)

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

Description

set Window Icon

License

Apache License

Declaration

public static void setWindowIcon(JFrame 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  ww . ja v a2 s  .  com

    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. setDefaultIcon(final JFrame window, final String imagepath)
  2. setIcon(javax.swing.JFrame jFrame, String icon)
  3. setIconImage(JFrame frame, Class clazz, String path)
  4. setIconImageFromResource(JFrame frame, String resource)
  5. setIconOnFrame(JFrame frame)