So far we have used the term widget without a formal definition. In the SWT class hierarchy, a Widget is the abstract class for any UI object that can be placed inside another widget. A Control is a widget that typically has a counterpart representation, denoted by an OS window handle, in the underlying platform.
We tend to use the terms widget and control interchangeably. Although the distinction matters in the SWT implementation, we don't focus on this difference from an application's point of view. If you review the SWT widget hierarchy, you will see that a Control is something that you can create and place anywhere you want in your widget parent/child tree. Widgets that are not controls are typically more specialized UI objects that can be created only for certain types of parents.
The SWT API reference and examples are full of information about the different kinds of controls and their usage. The org.eclipse.swt.widgets package defines the core set of widgets in SWT. The following table summarizes the concrete types of controls provided in this package and their purpose. (Abstract classes are eliminated from this list).
Widget
|
Purpose
|
Styles
|
Events |
---|---|---|---|
Selectable control that issues notification when pressed and/or released. |
BORDER, CHECK, PUSH,
RADIO, TOGGLE, FLAT, LEFT, RIGHT, CENTER, ARROW (with UP, DOWN)
|
Dispose, Control*, Selection | |
Composite control that provides a surface for drawing arbitrary graphics. Often used to implement custom controls. |
BORDER, H_SCROLL, V_SCROLL,
NO_BACKGROUND, NO_FOCUS, NO_MERGE_PAINTS, NO_REDRAW_RESIZE, NO_RADIO_GROUP
|
Dispose, Control* | |
An i-beam that is typically used as the insertion point for text. |
|
Dispose | |
Selectable control that allows the user to choose a string from a list of strings, or optionally type a new value into an editable text field. Often used when limited space requires a pop-down presentation of the available strings rather than using a single selection list box. |
BORDER, DROP_DOWN, READ_ONLY,
SIMPLE
|
Dispose, Control*, DefaultSelection, Modify, Selection | |
Control that is capable of containing other widgets. |
BORDER, H_SCROLL, V_SCROLL
|
Dispose, Control* | |
Composite control that allows users to dynamically reposition the cool items contained in the bar. |
BORDER
|
Dispose, Control* | |
Selectable user interface object that represents a dynamically positionable area of a cool bar. |
DROP_DOWN
|
Dispose | |
Composite control that groups other widgets and surrounds them with an etched border and/or label. |
BORDER, SHADOW_ETCHED_IN,
SHADOW_ETCHED_OUT, SHADOW_IN, SHADOW_OUT, SHADOW_NONE
|
Dispose, Control* | |
Non-selectable control that displays a string or an image. |
BORDER, CENTER, LEFT, RIGHT,
WRAP, SEPARATOR (with HORIZONTAL, SHADOW_IN, SHADOW_OUT, SHADOW_NONE, VERTICAL)
|
Dispose, Control* | |
Selectable control that allows the user to choose a string or strings from a list of strings. |
BORDER, H_SCROLL, V_SCROLL,
SINGLE, MULTI
|
Dispose, Control*, Selection, DefaultSelection | |
User interface object that contains menu items. |
BAR, DROP_DOWN, NO_RADIO_GROUP, POP_UP
|
Dispose, Help, Hide, Show | |
MenuItem | Selectable user interface object that represents an item in a menu. | CHECK, CASCADE, PUSH, RADIO, SEPARATOR | Dispose, Arm, Help, Selection |
Non-selectable control that displays progress to the user, typically in the form of a bar graph. |
BORDER, INDETERMINATE, SMOOTH, HORIZONTAL,
VERTICAL
|
Dispose, Control* | |
Selectable control that allows the user to drag a rubber banded outline of the sash within the parent window. Used to allow users to resize child widgets by repositioning their dividing line. |
BORDER, HORIZONTAL, VERTICAL
|
Dispose, Control*, Selection | |
Selectable control that represents a range of numeric values. |
BORDER, HORIZONTAL, VERTICAL
|
Dispose, Control*, Selection | |
ScrollBar | Selectable control that represents a range of positive numeric values. Used in a Composite that has V_SCROLL and/or H_SCROLL styles. | HORIZONTAL, VERTICAL | Dispose, Selection |
Window that is managed by the OS window manager. Shells can be parented by a Display (top level shells) or by another shell (secondary shells). |
BORDER, H_SCROLL, V_SCROLL,
CLOSE, MIN, MAX, NO_TRIM, RESIZE, TITLE (see also SHELL_TRIM, DIALOG_TRIM)
|
Dispose, Control*, Activate, Close, Deactivate, Deiconify, Iconify | |
Selectable control that represents a range of numeric values. A slider is distinguished from a scale by providing a draggable thumb that can adjust the current value along the range. |
BORDER, HORIZONTAL, VERTICAL
|
Dispose, Control*, Selection | |
Composite control that groups pages that can be selected by the user using labeled tabs. |
BORDER
|
Dispose, Control*, Selection | |
TabItem | Selectable user interface object corresponding to a tab for a page in a tab folder. | Dispose | |
Selectable control that displays a list of table items that can be selected by the user. Items are presented in rows that display multiple columns representing different aspects of the items. |
BORDER, H_SCROLL, V_SCROLL,
SINGLE, MULTI, CHECK, FULL_SELECTION, HIDE_SELECTION, VIRTUAL
|
Dispose, Control*, Selection, DefaultSelection | |
TableColumn | Selectable user interface object that represents a column in a table. | LEFT, RIGHT, CENTER | Dispose, Move, Resize, Selection |
TableItem | Selectable user interface object that represents an item in a table. | Dispose | |
Editable control that allows the user to type text into it. |
BORDER, SINGLE, READ_ONLY, LEFT, CENTER, RIGHT, WRAP, MULTI (with H_SCROLL, V_SCROLL)
|
Dispose, Control*, DefaultSelection, Modify, Verify | |
Composite control that supports the layout of selectable tool bar items. |
BORDER, FLAT, WRAP, RIGHT, SHADOW_OUT
HORIZONTAL, VERTICAL
|
Dispose, Control*, | |
ToolItem | Selectable user interface object that represents an item in a tool bar. | PUSH, CHECK, RADIO, SEPARATOR, DROP_DOWN | Dispose, Selection |
User interface object that implements rubber banding rectangles. |
LEFT, RIGHT, UP, DOWN, RESIZE
|
Dispose, Move, Resize | |
Selectable control that displays a hierarchical list of tree items that can be selected by the user. |
BORDER, H_SCROLL, V_SCROLL,
SINGLE, MULTI, CHECK
|
Dispose, Control*, Selection, DefaultSelection, Collapse, Expand | |
TreeItem | Selectable user interface object that represents a hierarchy of tree items in a tree. | Dispose |
Control* = Events inherited from Control: FocusIn, FocusOut, Help, KeyDown, KeyUp, MouseDoubleClick, MouseDown, MouseEnter, MouseExit, MouseHover, MouseUp, MouseMove, Move, Paint, Resize