Chapter 13. SWT Trees
Since the early days of the GUI a common element of interface design has been to present hierarchical information in a tree format. The grandfather of these interface types is the old Windows File Manager, which has evolved into Windows Explorer in today’s versions of Windows. Even Unix-based systems recognize the necessity for providing a tree control.
The SWT contains a set of classes that assist in the development of
tree interfaces. These classes are part of the
org.eclipse.swt.widgets
package. The two classes
examined in this chapter are
Tree
and TreeItem
. The
Tree
class represents the
trunk of the tree, to which
other items will be attached. TreeItem
objects
represent individual items (branches) of the tree.
Creating the Tree
The trunk of the tree is represented by
the Tree
class. To begin programming a tree
interface, you must create an instance of the Tree
class and add it to your Shell
or
Composite
.
How do I do that?
You create the Tree
object and add it to a
Shell
in the same manner as any other widget:
Tree t = new Tree(s, SWT.SINGLE | SWT.BORDER);
In addition to the common widget
styles
such as SWT.BORDER
, the
Tree
class supports three additional styles. These
are:
SWT.SINGLE
SWT.MULTI
SWT.CHECK
The preceding line of code creates a Tree
that
supports single selection of items. Later examples examine the
SWT.MULTI
and SWT.CHECK
tree
styles.
Get SWT: A Developer's Notebook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.