Re: Using Thread.sleep(..) and Swing Components




Peter Duniho wrote:
On Mon, 29 Sep 2008 10:30:37 -0700, <karpthomas@xxxxxxxxxxxxxx> wrote:

[...]
The problem is, that the component seems to be repainted only, when the method
is finished.

What am I doing wrong?

You are delaying the event-dispatch thread by calling sleep().

Operations that take any significant amount of time should be handled on a different thread, using the EventQueue.invokeLater() and EventQueue.invokeAndWait() methods to execute any code that is required to be executed on the EDT (such as setting the value of a progress bar control).


I find SwingWorker useful too. It simplifies the work of creating and using threads when you also want to update the GUI.


Just my ¤0.02 worth

--
RGB
.



Relevant Pages

  • Re: Using Thread.sleep(..) and Swing Components
    ... Operations that take any significant amount of time should be handled on a different thread, using the EventQueue.invokeLaterand EventQueue.invokeAndWaitmethods to execute any code that is required to be executed on the EDT (such as setting the value of a progress bar control). ...
    (comp.lang.java.programmer)
  • Re: Controling Event Sequencing...
    ... the framework will post a message to the message queue ... does not execute after the event is fired.... ... control exposes this event to the programmer to allow him / her to ... these system / control events will immidiately fire after the ...
    (microsoft.public.dotnet.languages.vb)
  • Re: More Before-The-Fact-Isms II, blocking viruses and spyware through NTFS
    ... > BUILTIN\Administrators Full Control ... > BUILTIN\CREATOR OWNER Special (Full Control except Execute) for Files ... but still can't launch any executables. ...
    (microsoft.public.security)
  • Re: Controling Event Sequencing...
    ... need the OnPostClick event fire after the OnClick event is completely ... event queue and have it execute AFTER the OnClick in completely done ... ... control exposes this event to the programmer to allow him / her to ... I inherit from this and create another button... ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Javascript Server-side Action Questions..
    ... How do you set the values from server-side to a client-side ... control or how do you execute a javascript function without a button click ... What ever asp.net control post back to your server even handler add ... there you can write your checkbox selection logic. ...
    (microsoft.public.dotnet.framework.aspnet)