ince Sun Microsystems released the first version of Java, the industry has been displeased with the way Java's front-end development toolkit works. Though Swing
appeased some developers with its look-and-feel, the interfaces one could build with it still lacked the right look and its performance did not meet the requirements of large-scale, industrial-strength applications.
To address this shortcoming, some folks like IBM set out to develop an entirely new toolkit that has a widget framework similar to Java's Abstract Window Toolkit (AWT) but is entirely dependent on the native operating system's GUI widgets. The result was the Standard Widget Toolkit (SWT), an open source Java graphical user interface (GUI) toolkit comprised of a widget set and a graphics library. Unlike AWT, SWT relies on the underlying operating system's native widgets, even if they are not present on other platforms. As a result, SWT enables client-side Java applications to assume the appearance and performance of traditional native desktop applications, albeit at the expense of portability.
Compared with AWT, SWT offers a number of benefits:
- UIs built on SWT are very similar to that of native applications.
- Resources are used more efficiently.
- Memory management is safer.
- Program logic is clearer.
- Performance improves.
- Fewer overall operating system threads are required.
In short, SWT widgets (UI components) let you create fast, native-looking GUIs for your Java applications. If platform independence is not a required feature for your application, SWT may be a very attractive option. Though application development with SWT involves some study, it is not a steep learning curve for Java programmers. This tutorial teaches the basic steps to get started with SWT and introduces the SWT widgets and their usages in a simple SWT application.
This section demonstrates the widgets that SWT provides and compares them with equivalent offerings in Swing. For those familiar with Swing, this is a good introduction to SWT.
Display and Shell
You need to create a display and a shell to hold the SWT widgets. A display is an object that contains all GUI components. It is not actually visible, but the components added to it are. Typically, you create only one display for an application.
A shell is a window within the application. You can create any number of shells for an application, attaching them at the top level (to a display) or to other shells.
Instances of the Display class manage the connection between SWT and the underlying operating system. Their most important function is to implement the SWT event loop in terms of the platform event model. This class has overall control over the operating system resources that SWT allocates. Display is analogous to JFrame and Shell is analogous to the Content pane in Swing.