如何打印带或不带标题栏的JFrame?
我的代码基本上如下所示:
BufferedImage image = ......
Graphics g = image.createGraphics();
jFrame.printAll(g);
当我查看图像时,标题栏区域始终为黑色...
有谁知道如何打印带标题栏或不带标题栏的 jFrame 吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
仅打印内容窗格。
Print just the content pane.
标题栏(和边框)不是由 Swing 绘制的,因为它们是您正在使用的平台的窗口。
如果您想获取整个帧的图像,则需要使用Robot.createScreenCapture()。 屏幕图像 类将为您轻松完成此操作。
然后你可以尝试打印创建的BufferedImage。我不确定执行此操作的最佳方法,但您可以使用缓冲图像创建一个 ImageIcon。然后您可以将图标添加到 JLabel,然后打印标签。在执行此操作之前,您可能需要调用 label.setSize( label.getPreferredSize() )。
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);
Try :
yourFrame.setUndecorated(true);