Is there a way to pause/resume the SwingWorker in Java ?
+1
A:
yes ,
- Create a class extending SwingWorker.
- Keep a static flag to make pause/resume mechanism in run method.
something like ..
while(){
sleep(1000);
if(shouldRun){
}
}
org.life.java
2010-10-04 07:32:24
+1
A:
You can pause the task you run in the swing worker by implementing something like this
while(true) {
if(paused)
{
try {
Thread.sleep(500); // half a second
continue;
} catch(InterruptedException e)
{
}
}
}
It is not very nice though.
Fedearne
2010-10-04 07:32:59
you copied code from here http://www.velocityreviews.com/forums/t136961-pausing-a-swing-worker-thread.html but forgot to write loop :-)
org.life.java
2010-10-04 07:34:31
Correct. Formatted it nicer though.
Fedearne
2010-10-04 07:41:48