Here you can find the source of setWindowIcon(JDialog jd)
public static void setWindowIcon(JDialog jd)
//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; } }