O'Reilly logo

Java Garage by Eben Hewitt

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Anatomy of a Swing App: Stuff You Typically Need to Do in Swing

Starting the App: InvokeLater()

First, the main method calls a static method from the javax.swing.SwingUtilities class called invokeLater(). This method is suited for starting the application, as its purpose is to update the GUI asynchronously on the event dispatching thread.

You can call this method from any thread if you want the event dispatching thread to run some code. If used in this way, it would be invoked like so:

Runnable updateGUI = new Runnable() {
    public void run() {
       new MyGUI();
    }
};
SwingUtilities.invokeLater(updateGUI);

Here, we just create a new object of a type called MyGUI, which probably extends JFrame or holds a JFrame member variable, sets up the properties ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required