The TreeView object is a widget for displaying trees and lists. The sole
purpose of this widget is for displaying the data on the screen and setting
other parts of the view using the associated objects.
Gtk Tree and List Widgets Overview
The standard tree and list widgets in Gtk are very powerful, but somewhat
complex. For your conveniance, the Java-Gnome project has derived a number of
simpler classes for common uses of these widgets.
SimpleList
- A single column list of string values.
- todo...
- todo...
If you choose not to use those, or your requirements are such that you
cannot use them, you will have to learn how to use the full objects.
There is only one widget which is placed in any applications to create
trees, lists and tables. This is the
TreeView
. An application can
have any number of treeviews and they can be placed as can normal widgets.
The data for the widget, and the method in which it is displayed is
controlled by other classes. Gtk has been designed so that any number of
treeview widgets can be linked to the same data store.
TreeViewColumn
s,
CellRenderer
s and
TreeSelection
s are
created for each view, so Views can use the same data store but have their
own column layout, data display within those columns (linked to any of the
dataBlocks in the store); and their own selections.
Models are used to store data. Data is stored in what could be considered
a table. There are a number of
DataColumn
s, which could be considered as
data columns (in fact, in the C version of gtk, they are always refered to as
columns; but this can get confused with TreeViewColumns which are quite a
different matter). These dataBlocks each store one type of data
(String, boolean, int, etc.). The 'rows' of the data table, or the individual
records in the data store are accessible using iterators called
TreeIter
s. These are used extensively in many methods. Setting data involves
getting an iterator (usually be creating a new row) and then setting the
value for each of the dataBlocks. The ordering of these dataBlocks has
absolutely no meaning - you can decide exactly which blocks are used on
screen by setting Attribute mappings to the CellRenderers which render data
on the screen (see below).
Currently, there are two implementations of
TreeModel
ListStore
- This is used for tables and lists. Data is organised
in rows and columns.
TreeStore
- This is for the hierarchical trees. Data is organised
using
TreePath
's.
Both trees and lists can have multiple columns of data. Columns are added
and removed using the
TreeView
class. Columns are objects which
determine how the data is displayed. They have settings such as the column
title, whether the column can be resized, and even whether the columns can be
reorganized (by dragging the columns). Each
TreeView
widget has it's
own set of columns. Determining how the data is displayed in the columns is
done by CellRenderers (see below). Any number of renderers can be added to
the same column
Tree and list `cells' may contain a large variety of data types.
Determining how they are displayed is done by the CellRenderer family of
classes. If the data is unusual, or you want to combine a number of data
types in a single column, you may construct your own renderer. However, you
are recommended to stick with the regular choices:
CellRendererPixbuf
-
CellRendererText
- For displaying Strings
CellRendererToggle
- For displaying boolean data, either as individual checkboxes or as radio
buttons.
The CellRenderer's need data to be able to display. This is set using the
TreeViewColumn.addAttributeMapping(CellRenderer,CellRendererAttribute,DataColumn)
. The renderer attributes vary with each
renderer, for example CellRendererText has a TEXT attribute for the text the
be displayed. The final parameter is for the dataBlock in the store in which
the data is contained.
Java-Gnome comes with a number of simple example applications involving trees.
They may be useful for learning the functionality of these classes.
activateCell
public void activateCell(TreePath path,
TreeViewColumn column)
Activates the cell determined by path and column.
path
- The TreePath to be activated.column
- The TreeViewColumn to be activated.
appendColumn
public int appendColumn(TreeViewColumn column)
Appends column to the list of columns.
column
- The GtkTreeViewColumn to add.
- The number of columns in tree_view after appending.
autoSizeColumns
public void autoSizeColumns()
Resizes all columns to their optimal width. Only works after the treeview has been realized.
collapseAll
public void collapseAll()
Recursively collapses all visible, expanded nodes.
collapseRow
public boolean collapseRow(TreePath path)
Collapses a row (hides its child rows, if they exist).
path
- Path to a row in the view
- TRUE if the row was collapsed.
expandAll
public void expandAll()
Recursively expands all nodes
expandRow
public boolean expandRow(TreePath path,
boolean openAll)
Opens the row so its children are visible.
path
- Path to a rowopenAll
- Whether to recursively expand, or just expand immediate
children
- TRUE if the row existed and had children
expandToPath
public void expandToPath(TreePath path)
Expands the row at path. This will also expand all parent rows of path as necessary.
path
- path to a row
- 2.2
findListener
protected static int findListener(Vector list,
Object listener)
Give us a way to locate a specific listener in a Vector.
- findListener in interface Widget
list
- The Vector of listeners to search.listener
- The object that is to be located in the Vector.
- Returns the index of the listener in the Vector, or -1 if
the listener is not contained in the Vector.
fireTreeViewEvent
protected void fireTreeViewEvent(TreeViewEvent event)
getAlternateRowColor
public boolean getAlternateRowColor()
getColumn
public TreeViewColumn getColumn(int position)
Gets the column at the given position in the tree view.
position
- The position of the column, counting from 0.
- The TreeViewColumn, or
null
if the position is outside the range
of columns.
getColumns
public TreeViewColumn[] getColumns()
Returns an array of all the columns currently in the view
getCursorColumn
public TreeViewColumn getCursorColumn()
Returns the current column
getCursorPath
public TreePath getCursorPath()
Returns the current path
getEnableSearch
public boolean getEnableSearch()
getEventListenerClass
public Class getEventListenerClass(String signal)
- getEventListenerClass in interface Container
getEventType
public EventType getEventType(String signal)
- getEventType in interface Container
getFixedHeightMode
public boolean getFixedHeightMode()
Returns whether fixed height mode is turned on for this TreeView.
getHAdjustment
public Adjustment getHAdjustment()
Gets the GtkAdjustment currently being used for the horizontal aspect.
- A GtkAdjustment object, or NULL if none is currently being used.
getHeadersVisible
public boolean getHeadersVisible()
Returns true if the headers on the TreeView are visible.
getHoverExpand
public boolean getHoverExpand()
Returns whether hover expansion mode is turned on for TreeView.
getHoverSelection
public boolean getHoverSelection()
Returns whether hover selection mode is turned on for this TreeView.
getModel
public TreeModel getModel()
Returns the model associated with this tree.
getReorderable
public boolean getReorderable()
getRowExpanded
public boolean getRowExpanded(TreePath path)
Returns TRUE if the node pointed to by path is expanded.
path
- A TreePath to test expansion state.
- TRUE if path is expanded.
getRowSeparatorMethod
public TreeViewRowSeparatorMethod getRowSeparatorMethod()
Get the object which is used to determine whether a row should be
drawn as a separator.
- The TreeViewRowSeparatorMethod or null
if no method has been set.
getSearchDataColumn
public DataColumn getSearchDataColumn()
Gets the column searched on by the interactive search code.
- A DataColumn object representing the column of the data model
in which the interactive search takes place.
getSelection
public TreeSelection getSelection()
Gets the TreeSelection associated with this widget
getType
public static Type getType()
Retrieve the runtime type used by the GLib library.
- getType in interface Container
getVAdjustment
public Adjustment getVAdjustment()
Gets the Adjustment currently being used for the vertical aspect.
gtk_tree_view_append_column
protected static final int gtk_tree_view_append_column(Handle treeView,
Handle column)
gtk_tree_view_collapse_all
protected static final void gtk_tree_view_collapse_all(Handle treeView)
gtk_tree_view_collapse_row
protected static final boolean gtk_tree_view_collapse_row(Handle treeView,
Handle path)
gtk_tree_view_columns_autosize
protected static final void gtk_tree_view_columns_autosize(Handle treeView)
gtk_tree_view_expand_all
protected static final void gtk_tree_view_expand_all(Handle treeView)
gtk_tree_view_expand_row
protected static final boolean gtk_tree_view_expand_row(Handle treeView,
Handle path,
boolean openAll)
gtk_tree_view_expand_to_path
protected static final void gtk_tree_view_expand_to_path(Handle treeView,
Handle path)
gtk_tree_view_get_bin_window
protected static final Handle gtk_tree_view_get_bin_window(Handle treeView)
gtk_tree_view_get_column
protected static final Handle gtk_tree_view_get_column(Handle treeView,
int n)
gtk_tree_view_get_columns
protected static final Handle[] gtk_tree_view_get_columns(Handle treeView)
gtk_tree_view_get_cursor
protected static final void gtk_tree_view_get_cursor(Handle treeView,
Handle path,
Handle focusColumn)
gtk_tree_view_get_enable_search
protected static final boolean gtk_tree_view_get_enable_search(Handle treeView)
gtk_tree_view_get_expander_column
protected static final Handle gtk_tree_view_get_expander_column(Handle treeView)
gtk_tree_view_get_hadjustment
protected static final Handle gtk_tree_view_get_hadjustment(Handle treeView)
gtk_tree_view_get_headers_visible
protected static final boolean gtk_tree_view_get_headers_visible(Handle treeView)
gtk_tree_view_get_model
protected static final Handle gtk_tree_view_get_model(Handle treeView)
gtk_tree_view_get_path_at_pos
protected static final boolean gtk_tree_view_get_path_at_pos(Handle treeView,
int x,
int y,
Handle path,
Handle column,
int cellX,
int cellY)
gtk_tree_view_get_reorderable
protected static final boolean gtk_tree_view_get_reorderable(Handle treeView)
gtk_tree_view_get_rules_hint
protected static final boolean gtk_tree_view_get_rules_hint(Handle treeView)
gtk_tree_view_get_search_column
protected static final int gtk_tree_view_get_search_column(Handle treeView)
gtk_tree_view_get_selection
protected static final Handle gtk_tree_view_get_selection(Handle treeView)
gtk_tree_view_get_type
protected static final int gtk_tree_view_get_type()
gtk_tree_view_get_vadjustment
protected static final Handle gtk_tree_view_get_vadjustment(Handle treeView)
gtk_tree_view_insert_column
protected static final int gtk_tree_view_insert_column(Handle treeView,
Handle column,
int position)
gtk_tree_view_move_column_after
protected static final void gtk_tree_view_move_column_after(Handle treeView,
Handle column,
Handle baseColumn)
gtk_tree_view_new
protected static final Handle gtk_tree_view_new()
gtk_tree_view_new_with_model
protected static final Handle gtk_tree_view_new_with_model(Handle model)
gtk_tree_view_remove_column
protected static final int gtk_tree_view_remove_column(Handle treeView,
Handle column)
gtk_tree_view_row_activated
protected static final void gtk_tree_view_row_activated(Handle treeView,
Handle path,
Handle column)
gtk_tree_view_row_expanded
protected static final boolean gtk_tree_view_row_expanded(Handle treeView,
Handle path)
gtk_tree_view_scroll_to_cell
protected static final void gtk_tree_view_scroll_to_cell(Handle treeView,
Handle path,
Handle column,
boolean useAlign,
double rowAlign,
double colAlign)
gtk_tree_view_scroll_to_point
protected static final void gtk_tree_view_scroll_to_point(Handle treeView,
int treeX,
int treeY)
gtk_tree_view_set_cursor
protected static final void gtk_tree_view_set_cursor(Handle treeView,
Handle path,
Handle focusColumn,
boolean startEditing)
gtk_tree_view_set_cursor_on_cell
protected static final void gtk_tree_view_set_cursor_on_cell(Handle treeView,
Handle path,
Handle focusColumn,
Handle focusCell,
boolean startEditin)
gtk_tree_view_set_enable_search
protected static final void gtk_tree_view_set_enable_search(Handle treeView,
boolean enableSearch)
gtk_tree_view_set_expander_column
protected static final void gtk_tree_view_set_expander_column(Handle treeView,
Handle column)
gtk_tree_view_set_hadjustment
protected static final void gtk_tree_view_set_hadjustment(Handle treeView,
Handle adjustment)
gtk_tree_view_set_headers_clickable
protected static final void gtk_tree_view_set_headers_clickable(Handle treeView,
boolean setting)
gtk_tree_view_set_headers_visible
protected static final void gtk_tree_view_set_headers_visible(Handle treeView,
boolean headersVisible)
gtk_tree_view_set_model
protected static final void gtk_tree_view_set_model(Handle treeView,
Handle model)
gtk_tree_view_set_reorderable
protected static final void gtk_tree_view_set_reorderable(Handle treeView,
boolean reorderable)
gtk_tree_view_set_rules_hint
protected static final void gtk_tree_view_set_rules_hint(Handle treeView,
boolean setting)
gtk_tree_view_set_search_column
protected static final void gtk_tree_view_set_search_column(Handle treeView,
int dataColumn)
gtk_tree_view_set_vadjustment
protected static final void gtk_tree_view_set_vadjustment(Handle treeView,
Handle adjustment)
handleSeparatorFunc
protected boolean handleSeparatorFunc(Handle model,
Handle iter)
insertColumn
public int insertColumn(TreeViewColumn column,
int position)
This inserts the column into the tree_view at position. If position is -1, then the column is inserted at the end.
column
- The GtkTreeViewColumn to be inserted.position
- The position to insert column in.
- The number of columns in tree_view after insertion.
moveColumn
public void moveColumn(TreeViewColumn column,
TreeViewColumn baseColumn)
Moves column to be after to baseColumn. If baseColumn is NULL, then
column is placed in the first position.
column
- The GtkTreeViewColumn to be moved.baseColumn
- The GtkTreeViewColumn to be moved relative to, or
NULL.
removeColumn
public int removeColumn(TreeViewColumn column)
Removes column from tree_view.
column
- The GtkTreeViewColumn to remove.
- The number of columns in tree_view after removing.
scrollToCell
public void scrollToCell(TreePath path)
Moves the alignments of the view to the position specified by
path.
path
- The path of the row to move to, or NULL.
scrollToCell
public void scrollToCell(TreePath path,
TreeViewColumn column)
Moves the alignments of the view to the position specified by column and
path.
path
- The path of the row to move tocolumn
- The TreeViewColumn to move horizontally to
scrollToCell
public void scrollToCell(TreePath path,
TreeViewColumn column,
double rowAlign,
double colAlign)
Moves the alignments of the view to the position specified
by column and path. rowAlign
determines where the row is placed, and colAlign
determines where column is placed. Both are expected to be
between 0.0 and 1.0. 0.0 means left/top alignment, 1.0
means right/bottom alignment, 0.5 means center.
path
- The path of the row to move tocolumn
- The TreeViewColumn to move horizontally torowAlign
- The vertical alignment of the row specified by path.colAlign
- : The horizontal alignment of the column specified by
column.
scrollToCell
public void scrollToCell(TreeViewColumn column)
Moves the alignments of the view to the position specified by column
column
- The TreeViewColumn to move horizontally to
scrollToPoint
public void scrollToPoint(int x,
int y)
Scrolls the TreeView such that the top-left corner of the visible
area is x, y, where x and y are specified in tree window coordinates.
If either x or y are -1 then that direction isn't scrolled.
x
- y
-
setAlternateRowColor
public void setAlternateRowColor(boolean setting)
This function tells GTK+ that the user interface for your application
requires users to read across tree rows and associate cells with one
another. By default, GTK+ will then render the tree with alternating
row colors. Do not use it just because you prefer the appearance of
the ruled tree; that's a question for the theme. Some themes will
draw tree rows in alternating colors even when rules are turned off,
and users who prefer that appearance all the time can choose those
themes. You should call this function only as a semantic hint to
the theme engine that your tree makes alternating colors useful
from a functional standpoint (since it has lots of columns,
generally).
setting
- TRUE if the tree requires reading across rows
setCursor
public void setCursor(TreePath path,
TreeViewColumn focusColumn,
boolean startEditing)
Sets the current keyboard focus to be at path, and selects it. This is
useful when you want to focus the user's attention on a particular
row. If column is specified, and
startEditing is TRUE, then editing should be started in the specified
cell. This function is often followed by
Widget.grabFocus()
in order to give keyboard focus to the widget. Please note that editing
can only happen when the widget is realized.
path
- A TreePathfocusColumn
- A TreeViewColumn, or NULLstartEditing
- TRUE if the specified cell should start being edited.
setCursor
public void setCursor(TreePath path,
TreeViewColumn focusColumn,
CellRenderer focusCell,
boolean startEditing)
Sets the current keyboard focus to be at path, and selects it. This is
useful when you want to focus the user's attention on a particular
row. If column is specified, and
startEditing is TRUE, then editing should be started in the specified
cell. If focusCell is also specified, the particular cellRenderer in that
column will get focusThis function is often followed by
Widget.grabFocus()
in order to give keyboard focus to the widget. Please
note that editing can only happen when the widget is realized.
path
- A TreePathfocusColumn
- A TreeViewColumn, or NULLfocusCell
- A cellrenderer, or nullstartEditing
- TRUE if the specified cell should start being edited.
- 2.2
setEnableSearch
public void setEnableSearch(boolean enableSearch)
If enable search is set, then the user can type in text to search through
the tree interactively.
enableSearch
- TRUE, if the user can search interactively
setExpanderColumn
public void setExpanderColumn(TreeViewColumn column)
Sets the column to draw the expander arrow at.
If column is NULL, then the expander arrow is always at the first visible
column.
column
- NULL, or the column to draw the expander arrow at.
setFixedHeightMode
public void setFixedHeightMode(boolean enable)
Enables or disables the fixed height mode of this TreeView. Fixed
height mode speeds up TreeView by assuming that all rows
have the same height. Only enable this option if all rows are
the same height and all columns are of type
TreeViewColumnSizing.FIXED
.
enable
- TRUE to enable fixed height mode.
setHAdjustment
public void setHAdjustment(Adjustment hadj)
Sets the Adjustment for the current horizontal aspect.
setHeadersClickable
public void setHeadersClickable(boolean setting)
Allow the column title buttons to be clicked.
setting
- TRUE if the columns are clickable.
setHeadersVisible
public void setHeadersVisible(boolean headersVisible)
Sets the the visibility state of the headers.
headersVisible
- TRUE if the headers are visibl
setHoverExpand
public void setHoverExpand(boolean expand)
Enables of disables the hover expansion mode of this
TreeView. Hover expansion makes rows expand or collaps if the
pointer moves over them.
expand
- TRUE to enable hover selection mode.
setHoverSelection
public void setHoverSelection(boolean hover)
Enables of disables the hover selection mode of this
TreeView. Hover selection makes the selected row follow the
pointer. Currently, this works only for the selection modes
SelectionMode.SINGLE
and
SelectionMode.BROWSE
.
hover
- TRUE to enable hover selection mode.
setModel
public void setModel(TreeModel model)
Sets the model for a GtkTreeView.
If the
TreeView
already has a model set,
it will remove it before setting the new model.
If model is NULL, then it will unset the old model.
model
- the new model for the TreeView
setReorderable
public void setReorderable(boolean reorderable)
This function is a convenience function to allow you to reorder models
that support the DragSourceIface and the DragDestIface. Both
TreeStore
and
ListStore
support these. If reorderable
is TRUE, then the user can reorder the model by dragging and dropping
rows. The developer can listen to these changes by adding listeners.
This function does not give you any degree of control over the order
-- any reorderering is allowed. If more control is needed, you should
probably handle drag and drop manually.
reorderable
- TRUE, if the tree can be reordered.
setRowSeparatorMethod
public void setRowSeparatorMethod(TreeViewRowSeparatorMethod method)
Set the object which is used to determine whether a row should be drawn
as a separator.
method
- The TreeViewRowSeparatorMethod or
null if no separators are to be drawn (the default).
setSearchDataColumn
public void setSearchDataColumn(DataColumn column)
Sets column as the column where the interactive search code should
search in. Additionally, turns on interactive searching.
column
- The column of the data model to search in.
setVAdjustment
public void setVAdjustment(Adjustment vadj)
Sets the Adjustment for the current vertical aspect.