Is there a way to convert a JPanel (that has not yet been displayed) to a BufferedImage?
thanks,
Jeff
Is there a way to convert a JPanel (that has not yet been displayed) to a BufferedImage?
thanks,
Jeff
From the BufferedImage you can create a graphics object, which you can use to call paint on the JPanel, something like:
public BufferedImage createImage(JPanel panel) {
int w = panel.getWidth();
int h = panel.getHeight();
BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
Graphics2D g = bi.createGraphics();
panel.paint(g);
return bi;
}
You may need to make sure you set the size of the panel first.
Basically I'm building a component that needs to get written to an image but not displayed
ScreenImage explains how to do what you want.
Take a look at BasicTableUI. The cell renderer is drawn on image without showing and then drawn on visible table component.