• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL

Part: I Widgets

Part I: Widgets

Traditionally, a widget is thought of as an abstract device that is useful for a particular purpose. The term is popular in economics. If you have ever studied economics in university, the professor probably asked, “How does an increase in supply affect the price of widgets?” when discussing the laws of supply and demand. We software developers have co-opted this word to represent those self-contained packages of code that are used to build most modern graphical user interfaces.[1] SWT is called the Standard Widget Toolkit because widgets really are the basis of any application built in SWT.

[1] You could argue that many user interfaces are now built from HTML or other XML-based descriptions. For example, although widgets are typically used to implement the input areas and scrolled frames that are found in Web pages, this is not relevant to the page designer. Despite this, all currently popular operating systems use widgets as the basis for their visual interfaces and devote a considerable portion of their code to implementing them.

Because widgets are so fundamental to developing applications, they are covered in detail in this part of the book. Each chapter covers a different aspect of the topic.

Widget Fundamentals: an overview of widgets and user interaction

The Keyboard: interacting with widgets via the keyboard

The Mouse: interacting with widgets via the mouse

Control Fundamentals: behaviors that widgets called controls share

Display: the connection between widgets and the underlying platform

Native Widgets: an overview of the native widgets

Basic Controls: the simplest controls in SWT

Tool Bars and Menus: controls that perform actions

Advanced Controls: tree, table, and tab folder controls

Range-Based Controls: controls that describe numeric ranges

Controls, Composites, Groups, and Shells: the container controls

Canvas and Caret: drawing area controls

Draggable Controls: controls that can manipulate the user interface

Dialogs: self-contained information windows and prompters

Layout: widget positioning and resizing support

The first four chapters describe what widgets are, their life cycle, and how users interact with them.

The Display chapter covers the class that represents the root of all widgets. Both its relationship to the rest of SWT and the specific API it provides are covered.

The Native Widgets chapter lists and briefly describes each of the native widgets. Following this chapter, there are a number of chapters that together provide complete descriptions of all of the native widgets provided by SWT: Basic Controls; Tool Bars and Menus; Advanced Controls; Range-Based Controls; Controls, Composites, Groups, and Shells; Canvas and Caret; and Draggable Controls.

The remaining two chapters provide both general descriptions of dialogs and layouts; they also have specific sections on each of the dialogs and layouts that are included with SWT.

If You Don't Read Anything Else…

If you are one of those people who learn by reading code and running it, this section is for you. In it, you will find “HelloWorld,” a minimal SWT program with a short description of each line of code and a list of the widget packages. If you want to run this code, you should read the section Running SWT Applications, but that's it. Enjoy!

HelloWorld in SWT

Here once again is a complete SWT program that creates and displays a new window on the desktop with “Hello, World.” in the title bar. This is a slight variation of the one described in the Using SWT chapter. Figure P1.1 shows the result of running this program on Windows XP.

01  import org.eclipse.swt.widgets.*;

02  public class HelloWorld {

03  public static void main(String[] args) {
04      Display display = new Display();
05      Shell shell = new Shell(display);
06      shell.setText("Hello, World.");
07      shell.setSize(200, 100);
08      shell.open();
09      while (!shell.isDisposed()) {
10          if (!display.readAndDispatch())
11              display.sleep();
12      }
13      display.dispose();
14  }



Not a subscriber?

Start A Free Trial

  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint