I would like to repaint component after each second, but it didn\'t work. What I am trying is:
try{
while(true){
Thread.currentThread
Make sure you're not hogging the UI-thread for this. If you're executing this loop in the UI-thread, then the repaint
event will never be dispatched.
Another note; sleep
is a static method, and should be invoked as Thread.sleep(...)
. (There is no way of doing thatThread.sleep(...)
anyway.)
The "correct" way of doing this is probably to use a SwingWorker
. Have a look at the tutorial.
If you provide more code, we can provide better answers.