Wizards - SWT - Application Window

Standalone SWT Application windows can be created using the SWT Application Window wizard. The wizard can be selected from the drop down Designer wizard menu or from the Eclipse New wizard.

To use the wizard, select the project source folder and package to contain the class. Then enter the class name and hit the Finish button.

Options are also provided to control the initial structure of the generated code. The contents of the window can be generated into a createContents() method, the windows open() method or the main() method itself.

 

The wizard generates the following code including a main() method and event loop.

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
 
public class SWTApplicationTest {
    protected Shell shell;
    public static void main(String[] args) {
        try {
            SWTApplicationTest window = new SWTApplicationTest();
            window.open();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public void open() {
        final Display display = Display.getDefault();
        createContents();
        shell.layout();
        shell.open();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch())
                display.sleep();
        }
    }
    protected void createContents() {
        shell = new Shell();
        shell.setSize(500, 375);
        shell.setText("SWT Application");
    }
}

SWT Application Windows can use any widget and layout manager.