I'm trying to learn about threads and JProgressBar.
I have a class that implements Runnable
. Let's say that the run()
just sleeps for 20 seconds and displays "Hello World".
Is it possible to create a JProgressBar that updates for as long as the thread is active?
If I had an int incrementer
, could I do something like this (it doesn't work, obviously, but is there something along these lines?):
while (Thread.isAlive()) {
incrementer++;
progress.setValue(incrementer);
Rectangle progressRect = progress.getBounds();
progressRect.x = 0;
progressRect.y = 0;
progress.paintImmediately( progressRect );
}
Thanks for any help.