Nick Ren
Nick Ren

Reputation: 65

How to print JFrame with or without Title Bar?

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

Answers (3)

camickr
camickr

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

blue_diamond
blue_diamond

Reputation: 65

Try : yourFrame.setUndecorated(true);

Upvotes: 0

Andrew Thompson
Andrew Thompson

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

Related Questions