Swing objects are not thread safe. SwingUtilities.invokeLater()
allows a task to be executed at some later point in time, as the name suggests; but more importantly, the task will be executed on the AWT event dispatch thread. When using invokeLater
, the task is executed asynchronously; there’s also invokeAndWait
, which won’t return until the task has finished executing.
Some information about the decision not to make Swing thread-safe can be found here: Multithreaded toolkits: A failed dream? [Archived]