Event dispatching thread: Difference between revisions

Content deleted Content added
Stolsvik (talk | contribs)
Swing and thread safety: Added a reference to tutorial from Oracle (former Sun) which states that UI components must be created and accessed on EDT.
corrected a statement about other threads executing code "in" the EDT (It's impossible for thread 1 to run "in" thread 2).
Line 23:
== Executing code in the EDT ==
 
Other application threads can executehave code executed in the event dispatching thread by defining the code in a {{Javadoc:SE|java/lang|Runnable}} object and pass it to the {{Javadoc:SE|javax/swing|SwingUtilities}} helper class or to the {{Javadoc:SE|java/awt|EventQueue}}. Two methods of these classes allow:
* synchronous code execution ({{Javadoc:SE|member=invokeAndWait(Runnable)|javax/swing|SwingUtilities|invokeAndWait(java.lang.Runnable)}} or {{Javadoc:SE|member=invokeAndWait(Runnable)|java/awt|EventQueue|invokeAndWait(java.lang.Runnable)}})
* and asynchronous code execution ({{Javadoc:SE|member=invokeLater(Runnable)|javax/swing|SwingUtilities|invokeLater(java.lang.Runnable)}} or {{Javadoc:SE|member=invokeLater(Runnable)|java/awt|EventQueue|invokeLater(java.lang.Runnable)}})