Screen Capture
For documentation purposes (and perhaps remote support), we need snapshot images of our application. So let's build such support directly into our application itself.
A part of "Gooey Beans, the GUI part of a trilogy in 42 parts"
We can capture whole desktop, and save it to a PNG file, as follows.
Alternatively, we might capture our JFrame, including its window decoration, as follows.
Code Snippets
public void captureScreen(String fileName) throws Exception {
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
BufferedImage image = new Robot().createScreenCapture(new Rectangle(screenSize));
ImageIO.write(image, "png", new File(fileName));
}
public void captureFrame(JFrame frame, String fileName) throws Exception {
BufferedImage image = new Robot().createScreenCapture(frame.getBounds());
ImageIO.write(image, "png", new File(fileName));
}





