Skip to content

Java SWT For Eclipse Plugin Widgets

Raviv Rachmiel edited this page Apr 25, 2017 · 1 revision

Java SWT:

A ¢ about Java-SWT:

The Standard Widget Toolkit (SWT) is the default user interface library used by Eclipse. It provides widgets, e.g., buttons and text fields, as well as layout managers. Layout managers are used to arrange the widgets according to a certain rule set. SWT supports several platforms, e.g., Windows, Linux and Mac OS X. The design target of SWT is to stay closely to the operating system (OS). The SWT API (Application Programming Interface) is very close to the native AP Iof the OS

Using SWT in a plug-in project

The SWT library is packaged as an Eclipse plug-in. If you create an Eclipse plug-in and want to use SWT you have to specify a dependency to the org.eclipse.swt plug-in in the corresponding manifest file.

A simple SWT code snippet:

package com.example.swt.widgets;

import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class FirstSWTApplication {

    public static void main(String[] args) {
        Display display = new Display();

        Shell shell = new Shell(display);

        // the layout manager handle the layout
        // of the widgets in the container
        shell.setLayout(new FillLayout());

        //TODO add some widgets to the Shell
        shell.open();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch()) {
                display.sleep();
            }
        }
        display.dispose();
    }
}

for a specific widget example - click here

Clone this wiki locally