Here you can find the source of componentToImage(Component component, int resolution)
public static BufferedImage componentToImage(Component component, int resolution) throws IOException
//package com.java2s; //License from project: GNU General Public License import java.awt.Component; import java.awt.Graphics2D; import java.awt.image.BufferedImage; import java.io.IOException; public class Main { public static BufferedImage componentToImage(Component component, int resolution) throws IOException { BufferedImage img = new BufferedImage(component.getWidth() * resolution, component.getHeight() * resolution, BufferedImage.TYPE_INT_ARGB_PRE); Graphics2D g2 = (Graphics2D) img.getGraphics(); g2.scale(resolution, resolution); g2.setColor(component.getForeground()); g2.setFont(component.getFont()); component.paintAll(g2);// w w w. j a v a 2s.c o m return img; } }