Possible Duplicate:
What does SwingUtilities.invokeLater do?
SwingUtilities.invokeLater
I have seen this little piece of code hundreds of times:
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
Now my question is: what does invokeLater()
do? What kind of bad things will happen if I just create and show my GUI inside the main thread?
1. Event Dispatcher Thread
is the GUI thread.
2. If you are talking about the main() method
...then its not long lived in Java Gui.
main()
method after scheduling the construction of GUI in EDT quits, now its EDT that handles the GUI.
3. invokeLater
means that this call will return immediately as the event is placed in Event Dispatcher Queue, and run()
method will run asynchronously...