Thread.Sleep() is freezing

Don’t ever call Thread.sleep(…) from within the Swing event thread as this will put the event thread itself to sleep. Since this thread is responsible for all Swing painting and user interaction, this will put your application to sleep.

If all you want is a delay in the display, then consider use of a Swing Timer.

If on the other hand your event thread is being compromised by a long-running task, then do the task in the background, using a SwingWorker (as suggested by Guillaume 1+ to him).

Leave a Comment