concept Table in category java

appears as: Table
Swt/Jface in Action: GUI Design with Eclipse 3.0

This is an excerpt from Manning's book Swt/Jface in Action: GUI Design with Eclipse 3.0.

Each widget—Tree, List, Table, and so on—has a matching Viewer subclass, such as ListViewer or TableViewer. The widget is intended to be matched with at most one instance of its Viewer, and once the Viewer has been associated with the widget, all manipulation should be done through the viewer instead of to the widget directly. Trying to mix calls between the widget and its viewer will have unpredictable results. All concrete Viewer subclasses provide a constructor that takes an instance of the appropriate widget and associates it with the new viewer. Alternatively, a constructor taking only a Composite is provided, which instantiates a widget as a child of the given Composite and binds it to the viewer.

Continuing SWT’s trend of intuitive widget names, a table is represented by a class named Table. The Table class isn’t terribly interesting. In general, if you’re using JFace, you’ll be better off interacting with a Table through the interface provided by a TableViewer, which we discuss later in the chapter. However, if you need to manipulate the currently selected table items directly, or you aren’t using JFace, you’ll need to use the underlying Table.

The first thing you’ll notice when looking at the methods available on Table is that although there are plenty of accessor methods to query its state, there is a distinct lack of setters that would let you customize the Table. In fact, rather than adding data or columns directly to the Table, you’ll pass a Table instance to the appropriate dependent class when that dependent is instantiated, similar to the way Composites are passed to other widgets rather than the widget being added to the Composite. Other than a few setters for straightforward display properties, such as header visibility, the critical methods to be aware of when manipulating a Table are summarized in table 9.1.

Table 9.1. Important Table methods

Method

Description

addSelectionListener() Notifies you when the table’s selection changes
select()/deselect() Overloaded in several ways to let you programmatically add or remove the selection on one or more items
getSelection() Retrieves an array of the currently selected items
remove() Removes items from the table
showItem()/showSelection() Forces the table to scroll until the item or selection is visible

It’s also important to remember that Table extends Scrollable and will therefore automatically come equipped with scrollbars unless you turn them off.