I have a problem.
I draw something using a loop and I use Sleep to pause the execution.
In the meantime, I want to be able to see what’s in a textArea, which has a lot of lines and I have to scroll down to see them.But I can’t.Using Sleep it’s not possible.
Any suggestions?
Thanks.
I have a problem. I draw something using a loop and I use Sleep
Share
Don’t use sleep on the event thread. I assume that yours is a Swing application (please tell us if this is correct or not), and if so, calling
Thread.sleep(...)on the event thread will put your whole GUI asleep making it unresponsive. Instead, if this is a Swing application, use a Swing Timer.Tutorial: How to Use Swing Timers
Edit 1
Note: there are many recommendations here to use a SwingWorker, and these can be useful, but I would hold off using them unless the code that needs to be done between the time gaps is very CPU intensive and takes a bit of time to complete, such as reading in a medium to large file. If all you’re doing is drawing a circle, then pausing, then drawing another circle, a SwingWorker is gross overkill and again a Swing Timer, which is much easier to implement, is the way to go.
As with all recommendations, the answers will depend on the specifics of your problem, and you may wish to tell us more.