New SwingWorker
Home ] Up ] Old SwingWorker ] An Old SwingWorker Example ] [ New SwingWorker ] A New SwingWorker Example ]

 

 

The original SwingWorker class used not to be part of the Java distribution, but a new version of it is now included in Java 6.0 (javax.swing.SwingWorker).

SwingWorker provides a number of communication and control features:

  • The SwingWorker subclass can define a method, done(), which is automatically invoked on the event dispatch thread when the background task is finished.
  • SwingWorker implements java.util.concurrent.Future. This interface allows the background task to provide a return value to the other thread. Other methods in this interface allow cancellation of the background task and discovering whether the background task has finished or been cancelled.
  • The background task can provide intermediate results by invoking SwingWorker.publish(), causing SwingWorker.process() to be invoked from the event dispatch thread.
  • The background task can define bound properties. Changes to these properties trigger events, causing event-handling methods to be invoked on the event dispatch thread.
 
The page was last updated February 19, 2008