I have a question to ask about Java Concurrency. I'm practicing Java Threading. What i do is create a simple interface which has a button and a JSlider. So when i click the button a variable will increase and the JSlider moving accordingly. Now I wonder if Swingworker is a right choice.
Asked
Active
Viewed 202 times
2 Answers
4
You only need to use SwingWorker for long-running tasks. What you describe will be performed instantly. Therefore you can do this on the Event Dispatch Thread, where all ActionListeners are performed.

Steve McLeod
- 51,737
- 47
- 128
- 184
-
I dont think so ... because the variable need to attach to the thread and increase gradually and the JSlider moving according to the variable value. If i used just the while loop to do this. The interface will be freezed – thelinh bui Sep 07 '12 at 14:00
-
1Then, yes, you can use SwingWorker. But there is also javax.swing.Timer, which is made for what you seem to be describing in the comment. – Steve McLeod Sep 07 '12 at 14:05
-
Do i have to call repaint() on the JSlider. Thanks – thelinh bui Sep 07 '12 at 14:09
-
3Please just, one question per page - but no, you don't need to call repaint. – Steve McLeod Sep 07 '12 at 14:15