You are on page 1of 1

Their only difference is indicated by their names: invokeLater simply schedules the task and

returns; invokeAndWait waits for the task to finish before returning.


An invokeLater() method is a static method of the SwingUtilities class

The SwingUtilities.invokeLater() method works like SwingUtilities.invokeAndWait() except that it puts the request on the event


queue and returns immediately. An invokeLater() method does not wait for the block of code inside the Runnable referred by
a target to execute.

java swing is not threadsafe, you can not update swing components like JButton, JLable, JTable
or JTree from any thread, they all need to be updated from just one thread and we call it Event
Dispatcher thread or EDT in short.

 Event Dispatcher thread is used to render graphics for java swing components and also process
all events corresponding to a keypress, mouse click or any action. 

So if you want to update a particular swing component suppose label of a JButton from Yes to
No you need to do this in Event Dispatcher thread and for doing this you need InvokeLater.
invokeLater is used to perform any task asynchronously on AWT Event Dispatcher thread.

Read more: https://javarevisited.blogspot.com/2011/09/invokeandwait-invokelater-swing-
example.html#ixzz6Q7c214MY

You might also like