Class SwingWorker

Class SwingWorker (in package javax.swing) enables you to perform an asynchronous task in a worker thread (such as a long-running computation) then update Swing components from the event dispatch thread based on the task’s results. SwingWorker implements the Runnable interface, meaning that a SwingWorker object can be scheduled to execute in a separate thread. The SwingWorker class provides several methods to simplify performing a task in a worker thread and making its results available for display in a GUI. Some common SwingWorker methods are described in Fig. 23.23.

Image

Fig. 23.23 | Commonly used SwingWorker methods.

Get Java™ How To Program (Early Objects), Tenth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.