SWT Programming with Eclipse, Page 3
The SWT GUI objects derived from Widget and Control classes. The Widget object is the base class and defines methods common to all GUI classes. The Control class is the base class of all the windowed GUI classes, which means that the components derived from Control require a window or dialog to be displayed.
Menu objects also require a window to be displayed, but this requirement is indirectly satisfied. A Menu object requires a Control object.
Figure 4. Widget class hierarchy.
Figure 4 shows the widget class hierarchy. The Widget, Item, ScrollBar, and Control classes are abstract classes.
8.1. Widget Events
Widget events are summarized in Table 3. For the sake of simplicity, the table contains only the event names. It is easy to figure out the name of an event class by using this <EventName>Event. Likewise, the name of the associated listener can be figured out by using <Listener Name>Listener. Each event does not have a matching adaptor class. For that reason, events having adaptors are marked in bold. The name of an adaptor can be figured out by using <EventName>Adaptor.
Event Name is a Control, event class is a ControlEvent, listener class is a ControlListener, adaptor class is a ControlAdaptor.
|Table 3. SWT Events|
|Event Name||Widgets||Generated When|
|Arm||MenuItem||a menu item is highlighted|
|Control||Control, TableColumn, Tracker||a control is resized or moved|
|Dispose||Widget||a widget is disposed|
|Focus||Control||a control gains or loses focus|
|Help||Control, Menu, MenuItem||the user requests help (e.g. by pressing the F1 key)|
|Key||Control||a key is pressed or released when the control has keyboard focus|
|Menu||Menu||a menu is hidden or shown|
|Modify||Combo, Text||a widget's text is modified|
|Mouse||Control||the mouse is pressed, released, or double-clicked over the control|
|MouseMove||Control||the mouse moves over the control|
|MouseTrack||Control||the mouse enters, leaves, or hovers over the control|
|Paint||Control||a control needs to be repainted|
|Selection||Button, Combo, CoolItem, List, MenuItem, Sash, Scale, ScrollBar, Slider, StyledText, TabFolder, Table, TableColumn, TableTree, Text, ToolItem, Tree||an item is selected in the control|
|Shell||Shell||the shell is minimized, maximized, activated, deactivated, or closed|
|Traverse||Control||the control is traversed (tabbed)|
|Tree||Tree, TableTree||a tree item is collapsed or expanded|
|Verify||Text, StyledText||a widget's text is about to be modified|
8.2. Useful widgets
Figure 5. Control class hierarchy.
All Control classes can be bordered. You can add a border to a control class by using the SWT.BORDER constant.
|SWT style constant|
|It is required to specify a style constant (style bit). If you do not know which constant to use or if you do not want to specify it, you can use SWT.NULL.|
A button can have different styles. The style of a button depends on its defined style bit. A list of buttons and their style constants is shown in Table 4.
|Table 4. SWT Button style bit constants and examples|
|SWT.ARROW||A button to show popup menus etc. Direction of the arrow is determined by the alignment constants.|
|SWT.CHECK||Check boxes can have images as well.|
|SWT.PUSH||A push button.|
|SWT.RADIO||Radio buttons can be used in a group.|
|SWT.TOGGLE||Like SWT.PUSH, but it remains pressed until a second click.|