From Horstmann’s “Core Java” vol. 1, Chapter 14 Multithreading/Threads and Swing:
Seemed like it might be worth quoting this pretty much as a whole. Five minutes of typing. Big deal.
Horstmann discusses the single-thread rule: “Do not touch Swing components in any thread other than the event dispatch thread.” Then, mentions that there are a few exceptions to this rule. For example, there are a number of Swing methods that are thread safe, and are marked so in the API with the sentence “This method is thread safe, although most Swing methods are not.”
He writes that originally, "any thread was allowed to construct components, set their properties, and add them into containers, as long as none of the components had been REALIZED. A component is realized if it can receive paint or validation events. This is the case as soon as the setVisible(true) or pack(!) methods have been invoked on the component, or if the component has been added to a container that has been realized.
"That version of the single-thread rule was convenient. It allowed you to create the GUI in the main method and then call setVisible(true) on the top-level frame of the application. There was no bothersome scheduling of a Runnable on the event dispatch thread.
"Unfortunately, some component implementors did not pay attention to the subtleties of the original single-thread rule. They launched activities on the event dispatch thread without ever bothering to check whether the component was realized. For example, if you call setSelectionStart or setSelectionEnd on a JTextComponent, a caret movement is scheduled in the event dispatch thread, even if the component is not visible.
"It might well have been possible to detect and fix these problems, but the Swing designers took the easy way out. They decreed that it is never safe to access components from any thread other than the event dispatch thread. Therefore, you need to construct the user interface in the event dispatch thread, using the call to EventQueue.invokeLater that you have seen in all our sample programs.
“Of course, there are plenty of programs that are not so careful and live by the old version of the single-thread rule, initializing the user interface on the main thread. Those programs incur the slight risk that some of the user interface initialization causes actions on the event dispatch thread that conflict with actions on the main thread…”
Any typos in the above, and the simplified formatting is due to my typing.