Reputation: 65
My code is basically like following:
BufferedImage image = ......
Graphics g = image.createGraphics();
jFrame.printAll(g);
When I view the image, the title bar area always black...
Does any know how to print jFrame with title bar or without title bar?
Upvotes: 0
Views: 1044
Reputation: 324128
When I view the image, the title bar area always black...
The title bar (and borders) are not painted by Swing since they are a window from the platform you are using.
If you want to get an image of the entire frame then you need to use Robot.createScreenCapture()
. The Screen Image class will do this easily for you.
Then you can try to print the BufferedImage that is created. I'm not sure the best way to do this, but you could just create an ImageIcon using the buffered image. Then you could add the icon to a JLabel and then print the label. You would probably need to invoke label.setSize( label.getPreferredSize() ) before doing this.
Upvotes: 3
Reputation: 168825
Does any know how to print jFrame with title bar or without title bar?
Print just the content pane.
jFrame.getContentPane().printAll(g);
Upvotes: 3