I have tried a lot, but can\'t seem to get it to work.
I was told to use EDT with the following example.
SwingUtilities.invokeLater(new Runnable(
I recommend you get the book Filthy Rich Clients. There's a chapter where they explain Swing's threading model to great detail.
Basically in Swing, any code that modifies the GUI should be executed in the Event Dispatcher Thread. The SwingUtilities
class that you are using there provides you with an easy way to post events to the event queue that is then dispatched by the EDT. That's what the invokeLater
method does, it takes a new Runnable()
as argument which is ultimately executed on the EDT.
From the book:
The invokeLater() implementation takes care of creating and queuing a special event that contains the Runnable. This event is processed on the EDT in the order it was received, just like any other event. When its time comes, it is dispatched by running the Runnable’s run() method.