Swing's Threading Policy:
In general, Swing is not thread safe. All Swing components and related classes must be accessed, unless otherwise documented, in the event submission thread.
Typical Swing applications process in response to an event generated from a user gesture. For example, clicking on a JButton will notify all the ActionListeners added to the JButton. As all events generated from a user gesture are sent in the sequence of sending the event, the restriction does not affect most of the developers.
However, where the impact lies is in building and displaying a Swing application. Calls to the main method of an application, or methods in Applet, are not invoked in the send thread of the event. As such, care must be taken to transfer control to the event's send thread when building and displaying an application or applet. The preferred way to transfer control and start working with Swing is to use invokeLater. The invokeLater method schedules a Runnable to be processed in the event's send thread. The following two examples work just as well to transfer the control and launch a Swing application:
import javax.swing.SwingUtilities;
public class MyApp implements Runnable {
public void run() {
// Invoked on the event dispatching thread.
// Construct and show GUI.
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new MyApp());
}
}
Or:
import javax.swing.SwingUtilities;
public class MyApp {
MyApp(String[] args) {
// Invoked on the event dispatching thread.
// Do any initialization here.
}
public void show() {
// Show the UI.
}
public static void main(final String[] args) {
// Schedule a job for the event-dispatching thread:
// creating and showing this application's GUI.
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new MyApp(args).show();
}
});
}
}
This restriction also applies to the models attached to the Swing components. For example, if a table model is connected to a JTable table, the table model should only be modified in the event distribution chain. If you modify the model in a separate thread, you run the risk of exceptions and possible damage to the display.
As all events are delivered in the event's sending thread, care should be taken in the processing of events. In particular, a long-running task, such as the io network or intensive computational processing, executed in the event sending thread blocks the sending of the event delivery chain so that it does not send other events. While the send thread of the event is blocked, the application does not respond completely to the user's input. Consult SwingWorker for the preferred way to perform such processing when working with Swing.
Information extracted from the java api and literally translated into Spanish, to see the original: link