How to remove the title bar from a JFrame screenshot?

Posted by Greg Harman on Stack Overflow See other posts from Stack Overflow or by Greg Harman
Published on 2010-12-23T04:37:29Z Indexed on 2010/12/23 4:54 UTC
Read the original article Hit count: 284

Filed under:
|
|
|

I'm capturing a screenshot image of a JFrame via a "double buffering" approach, per below:

public BufferedImage getScreenshot() {      
  java.awt.Dimension dim = this.getPreferredSize();         
  BufferedImage image = new BufferedImage(dim.width, dim.height, BufferedImage.TYPE_INT_RGB);            
  this.paint(image.getGraphics());      
  return image;     
}

where this extends JFrame. The image that I get has a blank strip along the top where the title bar was. What's the most straightforward way to capture an image of the contents of the JFrame without the extra space allocated for the title bar?

© Stack Overflow or respective owner

Related posts about java

Related posts about swing