[英]Java swingworker output
I have some code running in a swingworker, because it might cause the UI to block, I would like to revise the UI with the progress of the swingworker thread so I am using publish/process to revise a JLabel, which works, but there are other UI components that I would like to revise, is this the only thread safe way to do it, through the process method? 我在swingworker中运行一些代码,因为这可能会导致UI阻塞,我想根据swingworker线程的进度来修改UI,所以我正在使用发布/处理来修改JLabel,但是可以,但是我想修改的其他UI组件,这是通过process方法做到这一点的唯一线程安全方法吗?
I once got this exception when running it it, I assume it is because I was revising the UI components in the doInBackground method rather than from the process method? 我曾经在运行它时遇到过这个异常,我想这是因为我正在修改doInBackground方法中的UI组件,而不是从process方法中?
java.lang.Boolean cannot be cast to javax.swing.Painter
SwingWorker
provides progress functionality via the set/getProgress
methods and the support of the PropertyChangeListener
. SwingWorker
通过set/getProgress
方法以及PropertyChangeListener
的支持提供进度功能。
You can attach a PropertyChangeListener
to the SwingWorker
and monitor for the changes to the progress
property, updating the UI in the manner in which you need. 您可以将
PropertyChangeListener
附加到SwingWorker
并监视对progress
属性的更改,从而以所需的方式更新UI。
You would setProgress
from within side the doInBackground
method at the points you need to in order to update the progress state. 您可以在
doInBackground
方法的内部设置setProgress
,以更新进度状态。
Have a look at Issues with SwingWorker and JProgressBar for an example 看看有关SwingWorker和JProgressBar的问题的示例
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.