>>>>> "Paul" == Paul Brinkley <[EMAIL PROTECTED]> writes:
Paul> 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.
Paul> I couldn't tell you for sure whether it'd be safe based on the current
Paul> source code, but I can say with high certainty that it's probably not,
Paul> and definitely not something you can count on.
Paul> In general, -any- change to a Component's state - color, text, button
Paul> state, etc. - should be done only in the event dispatch thread (EDT).
Paul> The only exceptions are:
Paul> - repaint(), revalidate(), and invalidate()
Paul> - anything specifically marked as thread-safe
Paul> - anything done to a Component before it's displayed on screen
Paul> - anything done to an Applet before its start() method is called
Paul> I tend to put the least trust in the second criterion, since it
Paul> strikes me as the most likely to change from version to version. In
Paul> any case, I just looked up JComponent.setEnabled(), and it's not
Paul> mentioned as TS in the docs.
Paul> I encourage you to get comfortable with SwingUtilities.invokeLater(),
Paul> while organizing your code so that it needs to be called as little as
Paul> possible. It's not a bad little method once you get used to it. :-)
On the other hand, it's important to know that in the vast majority of
applications, in the vast majority of cases, if you're in a method
that needs to change the state of a Swing component, that you're very
likely already IN the EDT. For instance, any method that gets called
as a result of an event listener is in the EDT.
You only need to be concerned about this if you really know that your
application code is running on multiple threads. For instance, if
your client is a CORBA client and you have registered a callback
object with the server, then it's possible (likely) that your callback
code will be executed on a separate thread from the EDT.
--
===================================================================
David M. Karr ; w:(425)487-8312 ; TCSI & Best Consulting
[EMAIL PROTECTED] ; Java/Unix/XML/C++/X ; BrainBench CJ12P (#12004)
_______________________________________________
Swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/swing