Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EventQueue.invokeLater vrs SwingUtilities.invokeLater

Can someone highlight on the differences between these two and the instances both are required?!

I have an application which uses both intercheably, but want to know if one is better than the other. Obviously they both accept Runnable object, and so for me - I think I can use which one I like.

Why these two similar functions in different classes? I know one is in awt and the other Swing, but don't they do the same thing?

like image 650
Bitmap Avatar asked Apr 26 '12 12:04

Bitmap


People also ask

What is SwingUtilities invokeLater?

An invokeLater() method is a static method of the SwingUtilities class and it can be used to perform a task asynchronously in the AWT Event dispatcher thread. The SwingUtilities. invokeLater() method works like SwingUtilities. invokeAndWait() except that it puts the request on the event queue and returns immediately.

What is the difference between invokeAndWait and invokeLater?

Their only difference is indicated by their names: invokeLater simply schedules the task and returns; invokeAndWait waits for the task to finish before returning. You can see examples of this throughout the Swing tutorial: SwingUtilities. invokeLater(new Runnable() { public void run() { createAndShowGUI(); } });

What is EventQueue invokeLater?

invokeLater. public static void invokeLater(Runnable runnable) Causes runnable to have its run method called in the dispatch thread of the system EventQueue . This will happen after all pending events are processed.

What is SwingUtilities invokeLater new runnable ()?

SwingUtilities class has two useful function to help with GUI rendering task: 1) invokeLater(Runnable):Causes doRun. run() to be executed asynchronously on the AWT event dispatching thread(EDT). This will happen after all pending AWT events have been processed, as is described above.


1 Answers

SwingUtilities.invokeLater exists only because EventQueue.invokelater was introduced in 1.2, but Swing was available for 1.1. Swing in the JRE has always just called the EventQueue version. swingall.jar had some hack where it created a component, and executed pending operations on repaints.

invokeLater is about the EventQueue. I suggest using the method directly. SwingUtilities is just a dumping ground. I have seen a lot using SwingUtilities.invokeLater presumably in some kind of belief the Swing isn't dependent upon AWT.

like image 93
Tom Hawtin - tackline Avatar answered Sep 24 '22 06:09

Tom Hawtin - tackline