Top Description Fields Constructors Methods
org.eclipse.swt.widgets

public Class Tree

extends Composite
Class Inheritance
Imports
java.util.*, org.eclipse.swt.*, org.eclipse.swt.events.*, org.eclipse.swt.graphics.*, org.eclipse.swt.internal.*, org.eclipse.swt.internal.cairo.*, org.eclipse.swt.internal.gtk.*, org.eclipse.swt.internal.gtk3.*, org.eclipse.swt.internal.gtk4.*

Instances of this class provide a selectable user interface object that displays a hierarchy of items and issues notification when an item in the hierarchy is selected.

The item children that may be added to instances of this class must be of type TreeItem.

Style VIRTUAL is used to create a Tree whose TreeItems are to be populated by the client on an on-demand basis instead of up-front. This can provide significant performance improvements for trees that are very large or for which TreeItem population is expensive (for example, retrieving values from an external source).

Here is an example of using a Tree with style VIRTUAL:


 final Tree tree = new Tree(parent, SWT.VIRTUAL | SWT.BORDER);
 tree.setItemCount(20);
 tree.addListener(SWT.SetData, new Listener() {
     public void handleEvent(Event event) {
         TreeItem item = (TreeItem)event.item;
         TreeItem parentItem = item.getParentItem();
         String text = null;
         if (parentItem == null) {
             text = "node " + tree.indexOf(item);
         } else {
             text = parentItem.getText() + " - " + parentItem.indexOf(item);
         }
         item.setText(text);
         System.out.println(text);
         item.setItemCount(10);
     }
 });

Note that although this class is a subclass of Composite, it does not normally make sense to add Control children to it, or set a layout on it, unless implementing something like a cell editor.

Styles:
SINGLE, MULTI, CHECK, FULL_SELECTION, VIRTUAL, NO_SCROLL
Events:
Selection, DefaultSelection, Collapse, Expand, SetData, MeasureItem, EraseItem, PaintItem, EmptinessChanged

Note

Only one of the styles SINGLE and MULTI may be specified.

Important Note

This class is not intended to be subclassed.

See Also
Tree, TreeItem, TreeColumn snippets, SWT Example: ControlExample, Sample code and further information

Field Summary

Modifier and TypeField and Description
pack-priv GdkRGBA
pack-priv static final int
pack-priv boolean
pack-priv double
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv long
pack-priv int
pack-priv TreeColumn[]
pack-priv double
pack-priv TreeItem
pack-priv int
pack-priv GdkRGBA
pack-priv int
pack-priv boolean
pack-priv static final int
pack-priv boolean
firstCompute

True iff computeSize has never been called on this Tree

pack-priv boolean
pack-priv static final int
pack-priv GdkRGBA
pack-priv static final int
pack-priv static final int
pack-priv boolean
pack-priv Color
private long
pack-priv Color
pack-priv int
pack-priv ImageList
pack-priv boolean
pack-priv static final int
pack-priv long
pack-priv boolean
pack-priv ImageList
pack-priv boolean
isOwnerDrawn

The owner of the widget is responsible for drawing

pack-priv TreeItem[]
pack-priv boolean
pack-priv long
pack-priv int
pack-priv int
pack-priv boolean
pack-priv int
pack-priv boolean
pack-priv int
pack-priv int
pack-priv TreeColumn
pack-priv int
pack-priv TreeItem
pack-priv boolean
Inherited from org.eclipse.swt.widgets.Composite:
backgroundModechildrenLoweredembeddedHandlefixClipHandlefixClipMapimHandlelayoutlayoutCountNO_INPUT_METHODnoChildDrawingpopupChildsocketHandletabList

Constructor Summary

AccessConstructor and Description
public
Tree(Composite
a composite control which will be the parent of the new instance (cannot be null)
parent
,
int
the style of control to construct
style
)

Constructs a new instance of this class given its parent and a style value describing its behavior and appearance.

Method Summary

Modifier and TypeMethod and Description
pack-priv void
pack-priv TreeItem
pack-priv TreeItem
_getItem(long iter)

pack-priv TreeItem
_getItem(long parentIter, long iter, int index)

public void
addSelectionListener(SelectionListener
the listener which should be notified when the user changes the receiver's selection
listener
)

Adds the listener to the collection of listeners who will be notified when the user changes the receiver's selection, by sending it one of the messages defined in the SelectionListener interface.

public void
addTreeListener(TreeListener
the listener which should be notified
listener
)

Adds the listener to the collection of listeners who will be notified when an item in the receiver is expanded or collapsed by sending it one of the messages defined in the TreeListener interface.

pack-priv int
pack-priv void
bindArrowKeyBindings()

Binds the left and right arrow keys to allow for expanding and collapsing of the tree nodes.

pack-priv int
calculateWidth(long column, long iter, boolean recurse)

pack-priv long
cellDataProc(long tree_column, long cell, long tree_model, long iter, long data)

Overrides org.eclipse.swt.widgets.Widget.cellDataProc.

pack-priv boolean
pack-priv void
checkSetDataInProcessBeforeRemoval()

Check the tree for items that are in process of sending SWT#SetData event.

pack-priv static int
protected void
checkSubclass()

Overrides org.eclipse.swt.widgets.Composite.checkSubclass.

Checks that this class can be subclassed.
public void
clear(int
the index of the item to clear
index
,
boolean
true if all child items of the indexed item should be cleared recursively, and false otherwise
all
)

Clears the item at the given zero-relative index in the receiver.

pack-priv void
clear(long parentIter, int index, boolean all)

public void
clearAll(boolean
true if all child items should be cleared recursively, and false otherwise
all
)

Clears all the items in the receiver.

pack-priv void
clearAll(boolean all, long parentIter)

pack-priv Point
computeSizeInPixels(int wHint, int hHint, boolean changed)

Overrides org.eclipse.swt.widgets.Composite.computeSizeInPixels.

pack-priv void
copyModel(long oldModel, int oldStart, long newModel, int newStart, long oldParent, long newParent, int modelLength)

pack-priv void
createColumn(TreeColumn column, int index)

pack-priv void
pack-priv void
createItem(TreeColumn column, int index)

pack-priv void
createItem(TreeItem item, long parentIter, int index)

The fastest way to insert many items is documented in TreeItem#TreeItem(org.eclipse.swt.widgets.Tree, int, int) and TreeItem#setItemCount

pack-priv void
createRenderers(long columnHandle, int modelIndex, boolean check, int columnStyle)

pack-priv void
pack-priv GdkRGBA
pack-priv void
public void
deselect(TreeItem
the item to be deselected
item
)

Deselects an item in the receiver.

public void
deselectAll()

Deselects all selected items in the receiver.

pack-priv void
pack-priv void
public void
dispose()

Overrides org.eclipse.swt.widgets.Widget.dispose.

Disposes of the operating system resources associated with the receiver and all its descendants.
pack-priv boolean
dragDetect(int x, int y, boolean filter, boolean dragOnTimeout, boolean[] consume)

Overrides org.eclipse.swt.widgets.Control.dragDetect.

pack-priv void
pack-priv long
pack-priv int
pack-priv Rectangle
pack-priv int
public TreeColumn

Returns:

the column at the given index
getColumn
(int
the index of the column to return
index
)

Returns the column at the given, zero-relative index in the receiver.

public int

Returns:

the number of columns
getColumnCount
()

Returns the number of columns contained in the receiver.

public int[]

Returns:

the current visual order of the receiver's items
getColumnOrder
()

Returns an array of zero-relative integers that map the creation order of the receiver's items to the order in which they are currently being displayed.

public TreeColumn[]

Returns:

the items in the receiver
getColumns
()

Returns an array of TreeColumns which are the columns in the receiver.

pack-priv long[]
getColumnTypes(int columnCount)

pack-priv GdkRGBA
pack-priv GdkRGBA
pack-priv TreeItem
private GC
getGC(long cr)

public int

Returns:

the width of a grid line in points
getGridLineWidth
()

Returns the width in points of a grid line.

pack-priv int
public Color

Returns:

the receiver's header background color.
getHeaderBackground
()

Returns the header background color.

public Color

Returns:

the receiver's header foreground color.
getHeaderForeground
()

Returns the header foreground color.

public int

Returns:

the height of the header or zero if the header is not visible
getHeaderHeight
()

Returns the height of the receiver's header

pack-priv int
public boolean

Returns:

the receiver's header's visibility state
getHeaderVisible
()

Returns true if the receiver's header is visible, and false otherwise.

pack-priv int
getId(long iter, boolean queryModel)

public TreeItem

Returns:

the item at the given index
getItem
(int
the index of the item to return
index
)

Returns the item at the given, zero-relative index in the receiver.

public TreeItem

Returns:

the item at the given point, or null if the point is not in a selectable item
getItem
(Point
the point used to locate the item
point
)

Returns the item at the given point in the receiver or null if no such item exists.

public int

Returns:

the number of items
getItemCount
()

Returns the number of items contained in the receiver that are direct item children of the receiver.

public int

Returns:

the height of one item
getItemHeight
()

Returns the height of the area which would be used to display one of the items in the tree.

pack-priv int
pack-priv TreeItem
public TreeItem[]

Returns:

the items
getItems
()

Returns a (possibly empty) array of items contained in the receiver that are direct item children of the receiver.

pack-priv TreeItem[]
getItems(long parent)

public boolean

Returns:

the visibility state of the lines
getLinesVisible
()

Returns true if the receiver's lines are visible, and false otherwise.

public TreeItem

Returns:

the receiver's parent item
getParentItem
()

Returns the receiver's parent item, which must be a TreeItem or null when the receiver is a root.

pack-priv long
getPixbufRenderer(long column)

public TreeItem[]

Returns:

an array representing the selection
getSelection
()

Returns an array of TreeItems that are currently selected in the receiver.

public int

Returns:

the number of selected items
getSelectionCount
()

Returns the number of selected items contained in the receiver.

public TreeColumn

Returns:

the sort indicator
getSortColumn
()

Returns the column which shows the sort indicator for the receiver.

public int

Returns:

the sort direction
getSortDirection
()

Returns the direction of the sort indicator for the receiver.

pack-priv long
getTextRenderer(long column)

public TreeItem

Returns:

the item at the top of the receiver
getTopItem
()

Returns the item which is currently at the top of the receiver.

pack-priv long
pack-priv long
pack-priv long
pack-priv long
gtk_draw(long widget, long cairo)

Overrides org.eclipse.swt.widgets.Composite.gtk_draw.

pack-priv long
gtk_expand_collapse_cursor_row(long widget, long logical, long expand, long open_all)

Overrides org.eclipse.swt.widgets.Widget.gtk_expand_collapse_cursor_row.

pack-priv void
gtk_gesture_press_event(long
the corresponding controller responsible for capturing the event
gesture
,
int
how many touch/button presses happened with this one
n_press
,
double
the x coordinate, in widget allocation coordinates
x
,
double
the y coordinate, in widget allocation coordinates
y
,
long
the GdkEvent captured
event
)

Overrides org.eclipse.swt.widgets.Control.gtk_gesture_press_event.

Handling multi-press event on GTK4
pack-priv long
pack-priv long
pack-priv long
gtk_row_activated(long tree, long path, long column)

Overrides org.eclipse.swt.widgets.Widget.gtk_row_activated.

pack-priv long
pack-priv long
pack-priv long
pack-priv long
pack-priv long
pack-priv long
gtk_toggled(long renderer, long pathStr)

Overrides org.eclipse.swt.widgets.Widget.gtk_toggled.

pack-priv void
pack-priv void
pack-priv void
public int

Returns:

the index of the column
indexOf
(TreeColumn
the search column
column
)

Searches the receiver's list starting at the first column (index 0) until a column is found that is equal to the argument, and returns the index of that column.

public int

Returns:

the index of the item
indexOf
(TreeItem
the search item
item
)

Searches the receiver's list starting at the first item (index 0) until an item is found that is equal to the argument, and returns the index of that item.

pack-priv boolean
pack-priv boolean
pack-priv long
pack-priv void
propagateDraw(long
the parent container, i.e. fixedHandle
container
,
long
the cairo context provided by GTK
cairo
)

Overrides org.eclipse.swt.widgets.Composite.propagateDraw.

Propagates draw events from a parent container to its children using gtk_container_propagate_draw().

pack-priv void
reallocateIds(int newSize)

pack-priv void
pack-priv void
pack-priv void
pack-priv void
pack-priv void
releaseItem(TreeItem item, boolean release)

pack-priv void
releaseItems(long parentIter)

pack-priv void
pack-priv void
remove(long parentIter, int start, int end)

public void
removeAll()

Removes all of the items from the receiver.

public void
removeSelectionListener(SelectionListener
the listener which should no longer be notified
listener
)

Removes the listener from the collection of listeners who will be notified when the user changes the receiver's selection.

public void
removeTreeListener(TreeListener
the listener which should no longer be notified
listener
)

Removes the listener from the collection of listeners who will be notified when items in the receiver are expanded or collapsed.

pack-priv long
rendererGetPreferredWidthProc(long cell, long handle, long minimun_size, long natural_size)

Overrides org.eclipse.swt.widgets.Widget.rendererGetPreferredWidthProc.

pack-priv void
rendererRender(long cell, long cr, long snapshot, long widget, long background_area, long cell_area, long expose_area, long flags)

pack-priv long
rendererRenderProc(long cell, long cr, long widget, long background_area, long cell_area, long flags)

Overrides org.eclipse.swt.widgets.Widget.rendererRenderProc.

pack-priv long
rendererSnapshotProc(long cell, long snapshot, long widget, long background_area, long cell_area, long flags)

Overrides org.eclipse.swt.widgets.Widget.rendererSnapshotProc.

pack-priv void
pack-priv Point
pack-priv void
pack-priv boolean
public void
select(TreeItem
the item to be selected
item
)

Selects an item in the receiver.

public void
selectAll()

Selects all of the items in the receiver.

pack-priv void
sendMeasureEvent(long cell, long width, long height)

pack-priv void
sendTreeDefaultSelection()

Used to emulate DefaultSelection event.

pack-priv void
pack-priv void
pack-priv int
setBounds(int x, int y, int width, int height, boolean move, boolean resize)

Overrides org.eclipse.swt.widgets.Composite.setBounds.

public void
setColumnOrder(int[]
the new order to display the items
order
)

Sets the order that the items in the receiver should be displayed in to the given argument which is described in terms of the zero-relative ordering of when the items were added.

pack-priv void
pack-priv void
public void
setHeaderBackground(Color
the new color (or null)
color
)

Sets the header background color to the color specified by the argument, or to the default system color if the argument is null.

public void
setHeaderForeground(Color
the new color (or null)
color
)

Sets the header foreground color to the color specified by the argument, or to the default system color if the argument is null.

public void
setHeaderVisible(boolean
the new visibility state
show
)

Marks the receiver's header as visible if the argument is true, and marks it invisible otherwise.

public void
setInsertMark(TreeItem
the insert item. Null will clear the insertion mark.
item
,
boolean
true places the insert mark above 'item'. false places the insert mark below 'item'.
before
)

Display a mark indicating the point at which an item will be inserted.

pack-priv void
setItemCount(long parentIter, int count)

public void
setItemCount(int
the number of items
count
)

Sets the number of root-level items contained in the receiver.

public void
setLinesVisible(boolean
the new visibility state
show
)

Marks the receiver's lines as visible if the argument is true, and marks it invisible otherwise.

pack-priv void
setModel(long newModel)

pack-priv void
pack-priv void
pack-priv void
pack-priv void
setScrollWidth(long column, TreeItem item)

public void
setSelection(TreeItem
the item to select
item
)

Sets the receiver's selection to the given item.

public void
setSelection(TreeItem[]
the array of items
items
)

Sets the receiver's selection to be the given array of items.

public void
setSortColumn(TreeColumn
the column used by the sort indicator or null
column
)

Sets the column used by the sort indicator for the receiver.

public void
setSortDirection(int
the direction of the sort indicator
direction
)

Sets the direction of the sort indicator for the receiver.

public void
setTopItem(TreeItem
the item to be shown
item
)

Sets the item which is currently at the top of the receiver.

public void
showColumn(TreeColumn
the column to be shown
column
)

Shows the column.

pack-priv boolean
pack-priv void
showItem(long path, boolean scroll)

public void
showItem(TreeItem
the item to be shown
item
)

Shows the item.

public void
showSelection()

Shows the selection.

private void
pack-priv void
pack-priv void
pack-priv long
windowProc(long handle, long arg0, long user_data)

Overrides org.eclipse.swt.widgets.Control.windowProc.

Inherited from org.eclipse.swt.widgets.Composite:
_getChildren_getTabListadjustChildClippingchangedcheckBufferedcheckSubwindowcomputeTabListconnectFixedHandleDrawcreateHandledrawBackgrounddrawBackgroundInPixelsenableWidgetfindDeferredControlfindMenusfixChildrenfixClippingsfixModalfixParentGdkResourcefixStylefixTabListfixZOrderfocusHandleforceFocusgetBackgroundModegetChildrengetChildrenCountgetLayoutgetLayoutDeferredgetTabListgtk4_key_press_eventgtk_focusgtk_focus_in_eventgtk_focus_out_eventgtk_mapgtk_realizegtk_scroll_childgtk_style_updatedhasBorderhooksKeysimHandleisLayoutDeferredisTabGrouplayoutlayoutlayoutlayoutlayoutmarkLayoutminimumSizemoveAbovemoveBelowmoveChildrenmustBeVisibleOnInitBoundsparentingHandleprintWidgetredrawChildrenreleaseHandleremoveControlresizeHandlesetBackgroundModesetFocussetLayoutsetLayoutDeferredsetScrollBarVisiblesetTabGroupFocussetTabItemFocussetTabListshowWidgettoStringtranslateMnemonictranslateTraversaltraversalCodeupdateBackgroundModeupdateLayout