Chapter 3. Widgets: part 1

 

To the less enlightened, the term widget may suggest a gadget or gizmo—a mechanism that may or may not serve a useful purpose. But in studying SWT and JFace, you need to take widgets very seriously. These are the paints in your palette and the ingredients in your cupboard. Your understanding of the subject will determine how well your applications appear and perform.

The Eclipse designers define a widget as “any UI object that can be placed inside another widget.” However, rather than use this recursive definition, we’ve come up with our own: A widget is “any object in a graphical user interface that displays information and/or allows the user to interface with an application.”

We’ve used the word object on purpose, since every widget in an SWT/JFace GUI is the visual representation of an instance of a class. The goal of this chapter is to present many of these classes and show how you can configure their appearance. In particular, this chapter will cover three of the most important widget classes in SWT. We’ll start with one of the most common widgets, the Label. Then, we’ll add input capability to a label and learn about the Button class. Finally, we’ll discuss Composites, which are widgets capable of containing other widgets.

But first, we need to examine the Widget class, which resides at the top of the widget hierarchy, and its most important subclass, Control.

3.1. Introducing the Widget and Control classes

3.2. Labels

3.3. Involving the user with buttons

3.4. Containing components with Composites

3.5. Updating WidgetWindow

3.6. Summary