Stripies
Stripies

Reputation: 1267

SwingUtilities.invokeLater in AWT Event Dispatching Thread

Should you use SwingUtilities.invokeLater(Runnable) if you're modifying the GUI and you're in the AWT Event Dispatching Thread, such as an ActionListener?

Upvotes: 7

Views: 1212

Answers (1)

Tim Pote
Tim Pote

Reputation: 28029

You must always do GUI updates in the Event Dispatch Thread (EDT). However, as Jeffrey points out in the comments, the ActionListener.actionPerformed method on a Swing object is already invoked from the EDT.

If you simply want the JButton to look enabled/unenabled or to add/remove items from a JList, and your making those changes via an ActionListener on a Swing component, then you shouldn't have to invoke SwingUtilities.invokeLater explicitly.

Upvotes: 5

Related Questions