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?
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?
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
.
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.
You would setProgress
from within side the doInBackground
method at the points you need to in order to update the progress state.
Have a look at Issues with SwingWorker and JProgressBar for an example
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.