At 12:27 AM 3/8/2001 +0100, Sergio wrote:
>Content-Type: text/plain; charset=us-ascii; format=flowed
>Content-Transfer-Encoding: 7bit
>
>I'd like to know if there is some problem in invoking the setEnabled
>method of a JComponent from outside the event dispatching thread and,
>consequently, I have to make sure these calls are made in the event
>dispatching thread, or if this is not important.
>
>Thanks a lot.


I couldn't tell you for sure whether it'd be safe based on the current
source code, but I can say with high certainty that it's probably not,
and definitely not something you can count on.

In general, -any- change to a Component's state - color, text, button
state, etc. - should be done only in the event dispatch thread (EDT).
The only exceptions are:

- repaint(), revalidate(), and invalidate()
- anything specifically marked as thread-safe
- anything done to a Component before it's displayed on screen
- anything done to an Applet before its start() method is called

I tend to put the least trust in the second criterion, since it
strikes me as the most likely to change from version to version.  In
any case, I just looked up JComponent.setEnabled(), and it's not
mentioned as TS in the docs.

I encourage you to get comfortable with SwingUtilities.invokeLater(),
while organizing your code so that it needs to be called as little as
possible.  It's not a bad little method once you get used to it.  :-)


_______________________________________________
Advanced-swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/advanced-swing

Reply via email to