Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 783
Stripies Avatar asked May 14 '12 23:05

Stripies


1 Answers

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.

like image 94
Tim Pote Avatar answered Oct 27 '22 14:10

Tim Pote