Possible Duplicate:
Java Swing : ObtainImage
of JFrame
How do you save what a Java GUI Component displays to an image file?
E.g. rendering a JPanel as a PNG.
Possible Duplicate:
Java Swing : ObtainImage
of JFrame
How do you save what a Java GUI Component displays to an image file?
E.g. rendering a JPanel as a PNG.
JPanel panel = ...
...
...
File yourFileHere = ...
...
...
BufferedImage img = new BufferedImage(panel.getWidth(), panel.getHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics g = img.getGraphics();
panel.paint(g);
g.dispose();
try{
ImageIO.write(img, "png", yourFileHere);
}catch(IOException e){
e.printStackTrace();
}
that would be descibed and with excelent examples here by @Andrew Thompson, but you can learn more than that by reading 2D Graphics and examples for that here