Here you can find the source of createImageFromInvisibleComponent(JComponent component)
public static BufferedImage createImageFromInvisibleComponent(JComponent component)
//package com.java2s; //License from project: Open Source License import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics2D; import java.awt.GraphicsEnvironment; import java.awt.image.BufferedImage; import javax.swing.JComponent; public class Main { public static BufferedImage createImageFromInvisibleComponent(JComponent component) { Dimension componentSize = component.getPreferredSize(); component.setDoubleBuffered(false); component.setSize(componentSize); component.addNotify();/* w ww . j a v a2 s . c o m*/ component.validate(); BufferedImage img = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice() .getDefaultConfiguration().createCompatibleImage(component.getWidth(), component.getHeight()); Graphics2D grap = img.createGraphics(); grap.setColor(Color.WHITE); grap.fillRect(0, 0, img.getWidth(), img.getHeight()); component.print(grap); grap.dispose(); return img; } }