Skip to content

Instantly share code, notes, and snippets.

@arumoy
Last active February 4, 2016 05:15
Show Gist options
  • Save arumoy/5f592de94fb23d1ef9e5 to your computer and use it in GitHub Desktop.
Save arumoy/5f592de94fb23d1ef9e5 to your computer and use it in GitHub Desktop.
Take screenshot of a particular JFrame in Swing(Java)
private void scrshtActionPerformed() {
/**
* this gist outline the process to grab the screenshot of a particular
* JFrame in Swing from which the method is invoked
*
* "this" is the particualr frame here
* */
BufferedImage screenshotImage = new BufferedImage(
this.getBounds().width, this.getBounds().height,
BufferedImage.TYPE_INT_RGB);
this.paint(screenshotImage.getGraphics());
try {
ImageIO.write(screenshotImage, "png", new File("screenShot.png" ));
} catch (IOException ex) {
System.err.println("ImageIsuues");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment