如何打印带或不带标题栏的JFrame?

发布于 2024-12-27 13:58:11 字数 199 浏览 3 评论 0原文

我的代码基本上如下所示:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

御守 2025-01-03 13:58:11

有人知道如何打印带标题栏或不带标题栏的 jFrame 吗?

仅打印内容窗格。

jFrame.getContentPane().printAll(g);

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

Print just the content pane.

jFrame.getContentPane().printAll(g);
放血 2025-01-03 13:58:11

当我查看图像时,标题栏区域始终为黑色...

标题栏(和边框)不是由 Swing 绘制的,因为它们是您正在使用的平台的窗口。

如果您想获取整个帧的图像,则需要使用Robot.createScreenCapture()。 屏幕图像 类将为您轻松完成此操作。

然后你可以尝试打印创建的BufferedImage。我不确定执行此操作的最佳方法,但您可以使用缓冲图像创建一个 ImageIcon。然后您可以将图标添加到 JLabel,然后打印标签。在执行此操作之前,您可能需要调用 label.setSize( label.getPreferredSize() )。

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.

甜心小果奶 2025-01-03 13:58:11

尝试:yourFrame.setUndecorated(true);

Try : yourFrame.setUndecorated(true);

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文