Chapter 2. SWT Shells

The foundation from which you build every GUI is the window, so it’s appropriate to begin discussion of the SWT by examining the classes that provide you with the ability to rapidly develop windows of all types.

If you look at all the different operating systems available, you soon realize that GUI windows come in all manner of types. These windows look and behave differently on the MS Windows platform than they do on Motif running under Unix, or KDE running under Linux. Even on a single platform, GUI windows may look and behave differently across versions—compare, for example, applications running under Windows 95, 98, NT, 2000, or XP. Fortunately for us developers, the code necessary to manage these differences is contained in the SWT library for a particular platform and is nicely abstracted for us in the SWT Java classes that we use to access that library. You write your code once, and allow the SWT native library to handle the differences between platforms.

We use two SWT classes to create windows: Display and Shell. Display is the class responsible for managing the interaction between all SWT widgets and the underlying operating system. It is in Display that you find methods that enable you to directly query the operating system for information about things such as which control currently has the focus and what windows are currently open and attached to the display. You will not need to interact directly with the display very often.

The second class, ...

Get SWT: A Developer's Notebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.