Are there any differences between EventQueue.invokeLater()
and SwingUtilities.invokeLater()
?
Or is that the latter is just built on top of the former (with no modifications) for the sake of design?
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.
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.
Difference on InvokeLater vs InvokeAndWait in Swing 1) InvokeLater is used to perform a task asynchronously in AWT Event dispatcher thread while InvokeAndWait is used to perform task synchronously. 2) InvokeLater is a non-blocking call while InvokeAndWait will block until the task is completed.
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.
SwingUtilities class was built to combine all general utility methods used in swing to be in one single class. Internally SwingUtilities.invokeLater()
calls EventQueue.invokeLater()
1197 public static void invokeLater(Runnable doRun) { 1198 EventQueue.invokeLater(doRun); 1199 }
Reference: http://kickjava.com/src/javax/swing/SwingUtilities.java.htm
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With