简体   繁体   中英

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?

Does any know how to print jFrame with title bar or without title bar?

Print just the content pane.

jFrame.getContentPane().printAll(g);

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.

试试: yourFrame.setUndecorated(true);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM