I am using JProgressBar for Showing The Progress Of Data Loaded From from DataBase . I am using SwingWorker Class To Load The Data In BackGround Thread using Tutorial!
T
You can implement Runnable
; it avoids Future
and generics, but it is easy to get wrong.
This answer compares SwingWorker and Runnable for similar action; SwingWorker
has the advantage, but it requires better knowledge about Java Essential Classes
.
SwingWorker
is proper way and is designated for single long running thread; for multithreading, invoke SwingWorker
from Executor
.
Example about SwingWorker.
Example about get() exceptions from SwingWorker and PropertyChangeListener.
@mKorbel has cited many instructive examples, but the key is invoking setProgress()
from the worker's doInBackground()
. SwingWorker
handles the required synchronization. Several helpful answers expand on the topic in this related Q&A, including a reference to this example.