EventQueue.invokeLater vrs SwingUtilities.invokeLater

Can someone highlight the differences between the two and the instances required ??

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

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

+6
source share
3 answers

SwingUtilities.invokeLater exists only because EventQueue.invokelater was introduced in 1.2, but Swing was available for 1.1. The swing in the JRE has always been called the EventQueue version EventQueue . swingall.jar had some hack where he created the component, and performed unfinished operations on repaint.

invokeLater has an EventQueue value. I suggest using the method directly. SwingUtilities is just a dump. I have seen a lot using SwingUtilities.invokeLater presumably in some kind of belief that Swing is not dependent on AWT.

+12
source

Actually code SwingUtilities # invokeLater (Runnable doRun) :

 public static void invokeLater(Runnable doRun) { EventQueue.invokeLater(doRun); } 

So this is the same!

+5
source

As described in javadoc, they are the same, for example. copy-paste from invokeAndWait javadoc method

Starting from 1.3, this method is just a cover for java.awt.EventQueue.invokeAndWait ()

So you can mix them, and no matter which version you use.

+4
source

Source: https://habr.com/ru/post/914227/


All Articles