Your Swing GUI needs to run on the the Event Dispatch Thread (EDT). The main
function, when started by the Java VM, is not on the EDT. So it's up to you to make sure your GUI starts on the EDT by using invokeLater()
.
What might be confusing is that if you don't use invokeLater()
things will probably still work. So what's all the fuss? Well, one day, when you least expect it, things won't work and this will be the cause.
More info can be found here: Initial Threads.