9.14. Creating Tables
Problem
You have a lot of data you need to present visually, and you want to arrange that data in columns.
Solution
Use an SWT table based on the Table class. SWT
tables can display columns of text, images, checkboxes, and more.
Discussion
Here’s a selection of the Table
class’s methods:
-
void addSelectionListener(SelectionListener listener) Adds the listener to the collection of listeners that are notified when the table’s selection changes
-
void deselect(int index) Deselects the item at the given zero-relative index in the table
-
TableItem[] getSelection( ) Returns an array of
TableItemobjects that are selected in the table-
int getSelectionIndex( ) Returns the zero-relative index of the item which is currently selected in the table (
-1if no item is selected)-
int[] getSelectionIndices( ) Returns the zero-relative indices of the items that are currently selected in the table
-
boolean isSelected(int index) Returns
trueif the item is selected,falseotherwise-
void select(int index) Selects the item at the given zero-relative index in the table
As an example (TableApp at this
book’s site), we’ll create a simple
table displaying text items that catches selection events.
We’ll create a new table and stock it with items
using the TableItem class, then report which item
has been selected in a text widget. Here are some popular
TableItem class methods:
-
boolean getChecked( ) Returns
trueif the table item is checked,falseotherwise-
boolean getGrayed( ) Returns
trueif the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access