Java的swing print()用法 [英] Java's swing print() usage

查看:67
本文介绍了Java的swing print()用法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

java的swing print()是否必须在EDT(事件调度线程)上调用?

Does java's swing print() have to be called on the EDT (event dispatch thread)?

众所周知,执行需要很长时间,而在 EDT 上长时间运行的事情很痛苦.

It is taking an extended amount of time to execute and long running things being on the EDT are a pain, as we all know.

推荐答案

简而言之,不,打印不需要在 EDT 上进行.

Short answer, no, the printing does not need to take place on the EDT.

官方教程中介绍了这一点:如何打印文本

This is covered in the official tutorial: How to Print Text

交互式或非交互式打印

在交互模式下,会在打印期间显示带有中止选项的进度对话框.这是进度对话框的示例.

In interactive mode a progress dialog with an abort option is shown for the duration of printing. Here is a sample of a progress dialog.

此对话框允许用户跟踪打印进度.当在事件调度线程上调用打印方法时,进度对话框是模态的,否则是非模态的.重要的是您的文档在打印时保持不变,否则打印行为是未定义的.打印方法可确保您的文档不会被更改并在打印期间禁用该组件.

This dialog allows the user to keep track of printing progress. The progress dialog is modal when the print method is called on the event dispatch thread and non-modal otherwise. It is important that your document remain unchanged while being printed, otherwise the printing behavior is undefined. The print method ensures that your document will not be changed and disables the component for the duration of printing.

如果在非交互模式下调用事件调度线程上的打印方法,那么包括重绘在内的所有事件都会被阻塞.这就是为什么仅建议对具有不可见 GUI 的应用程序在 EDT 上进行非交互式打印.

If you call the print method on the event dispatch thread in non-interactive mode, then all events including repaints will be blocked. That is why printing non-interactively on EDT is only recommended for applications with non-visible GUI.

这篇关于Java的swing print()用法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆