class org.aswing.JTree extends Container
Interfaces | |||||
CellEditorListener, TreeModelListener, Viewportable |
|
A control that displays a set of hierarchical data as an outline.
A specific node in a tree can be identified either by a
TreePath
(an object that encapsulates a node and all of its ancestors), or by its
display row, where each row in the display area displays one node.
An expanded node is a non-leaf node (as identified by
TreeModel.isLeaf(node)
returning false) that will displays
its children when all its ancestors are expanded.
A collapsed node is one which hides them. A hidden node is one which is under a collapsed ancestor. All of a viewable nodes parents are expanded, but may or may not be displayed. A displayed node is both viewable and in the display area, where it can be seen.
The following JTree
methods use "visible" to mean "displayed":
isRootVisible()
setRootVisible()
scrollPathToVisible()
scrollRowToVisible()
getVisibleRowCount()
setVisibleRowCount()
The next group of JTree
methods use "visible" to mean
"viewable" (under an expanded parent):
isPathVisible()
makePathVisible()
If you are interested in knowing when the selection listen the
the TreeSelectionEvent.TREE_SELECTION_CHANGED
event.
If you are interested in detecting either double-click events or when a user clicks on a node, regardless of whether or not it was selected, we recommend you do the following:
yourTree.addEventListener(MouseEvent.MOUSEDOWN, onPressed); .... public function _onPressed(e:Event):void { var selPath:TreePath = tree.getMousePointedPath(); .... }
To use JTree
to display compound nodes
(for example, nodes containing both
a graphic icon and text), subclass TreeCell
and TreeCellFactory
and use
setCellFactory
to tell the tree to use it. To edit such nodes,
subclass TreeCellEditor
and use setCellEditor
.
For a big model tree, there's two way to speed up the performance. E.g. call JTree.setFixedCellWidth(width:int) to fix the cell width.
@see TreeModel
Authors: paling, ngrebenshikov
Show Events | Hide Events
|
Class Fields
static var CONTIGUOUS_TREE_SELECTION:Int
Selection can only be contiguous. This will only be enforced if a RowMapper instance is provided. That is, if no RowMapper is set this behaves the same as DISCONTIGUOUSTREESELECTION.
static var DISCONTIGUOUS_TREE_SELECTION:Int
Selection can contain any number of items that are not necessarily contiguous.
static var EXPANDS_SELECTED_PATHS_PROPERTY:String
Bound property name for expands selected paths property
static var INVOKES_STOP_CELL_EDITING_PROPERTY:String
Bound property name for messagesStopCellEditing
.
Instance Fields
var cellFactory:TreeCellFactory
The cell used to draw nodes. If null
, the UI uses a default cellRenderer
.
If true, any time the selection is changed, either via the
TreeSelectionModel
, or the cover methods provided by
JTree
, the TreePath
s parents will be
expanded to make them visible (visible meaning the parent path is
expanded, not necessarily in the visible rectangle of the
JTree
). If false, when the selection
changes the nodes parent is not made visible (all its parents expanded).
This is useful if you wish to have your selection model maintain paths
that are not always visible (all parents expanded).
var fixedCellWidth:Int
The width of every cell in the list.
If width
is -1,
cell widths are computed by applying TreeCell.getPreferredSize()
for each list element.
The default value of this property is -1.
If your tree model is very large or all of your tree item has same width, we recommend you set a fixed cell with it will speed up the performance.
See setRowHeight()
var invokesStopCellEditing:Bool
If true, when editing is to be stopped by way of selection changing,
data in tree changing or other means stopCellEditing
is invoked, and changes are saved. If false,
cancelCellEditing
is invoked, and changes
are discarded. Default is false.
var rootVisible:Bool
True if the root node is displayed, false if its children are the highest visible nodes.
Height to use for each display row. If this is <= 0 the renderer determines the height for each row.
var rowHeightSet:Bool
Whether or not row height is set by user. If it is set by user, the LAF will not change the row height value.
var scrollsOnExpand:Bool
If true, when a node is expanded, as many of the descendants are scrolled to be visible.
Whether or not scrolls on expand is set by user. If it is set by user, the LAF will not change the scrolls on expand value.
var selectionBackground:ASColor
The background color for selected cells. Cell renderers can use this color to render text and graphics for selected cells.
The default value of this property is defined by the look and feel implementation.
See selectionForeground
, foreground
, background
, font
var selectionForeground:ASColor
The foreground color for selected cells. Cell renderers can use this color to render text and graphics for selected cells.
The default value of this property is defined by the look and feel implementation.
See selectionBackground
, foreground
, background
, font
var visibleRowCount:Int
Number of rows to make visible at one time. This value is used for
the Scrollable
interface. It determines the preferred
size of the display area.
function addSelectionInterval(index0:Int, index1:Int, ?programmatic:Bool = true): Void
Adds the paths between index0 and index1, inclusive, to the selection.
index0 | an integer specifying a display row, where 0 is the first row in the display |
index1 | an integer specifying a second display row |
programmatic | indicate if this is a programmatic change |
function addSelectionListener(listener:Dynamic ->Void?priority:Int = 0, ?useWeakReference:Bool = false): Void
Adds a listener for tree selection events. the listenerthat will be notified when a node is selected or deselected (a "negative selection")
listener | the new listener to be added |
priority | the priority |
useWeakReference | Determines whether the reference to the listener is strong or weak. |
function addSelectionPath(path:TreePath, ?programmatic:Bool = true): Void
Adds the node identified by the specified TreePath
to the current selection. If any component of the path isn't
viewable, and getExpandsSelectedPaths
is true it is
made viewable.
Note that JTree
does not allow duplicate nodes to
exist as children under the same parent -- each sibling must be
a unique object.
path | the |
programmatic | indicate if this is a programmatic change |
function addSelectionPaths(paths:Array<Dynamic>, ?programmatic:Bool = true): Void
Adds each path in the array of paths to the current selection. If
any component of any of the paths isn't viewable and
getExpandsSelectedPaths
is true, it is
made viewable.
Note that JTree
does not allow duplicate nodes to
exist as children under the same parent -- each sibling must be
a unique object.
paths | an array of |
programmatic | indicate if this is a programmatic change |
function addSelectionRow(row:Int, ?programmatic:Bool = true): Void
Adds the path at the specified row to the current selection.
row | an integer specifying the row of the node to add, where 0 is the first row in the display |
programmatic | indicate if this is a programmatic change |
function addSelectionRows(rows:Array<Dynamic>, ?programmatic:Bool = true): Void
Adds the paths at each of the specified rows to the current selection.
rows | an array of ints specifying the rows to add, where 0 indicates the first row in the display |
programmatic | indicate if this is a programmatic change |
function addStateListener(listener:Dynamic ->Void?priority:Int = 0, ?useWeakReference:Bool = false): Void
Add a listener to listen the viewpoat state change event.
When the viewpoat's state changed, the state is all about:
- viewPosition
- verticalUnitIncrement
- verticalBlockIncrement
- horizontalUnitIncrement
- horizontalBlockIncrement
listener | the listener |
priority | the priority |
useWeakReference | Determines whether the reference to the listener is strong or weak. |
function cancelEditing(): Void
Cancels the current editing session. Has no effect if the tree isn't being edited.
function clearSelection(?programmatic:Bool = true): Void
Clears the selection.
programmatic | indicate if this is a programmatic change |
function collapsePath(path:TreePath): Void
Ensures that the node identified by the specified path is collapsed and viewable.
path | the |
function collapseRow(row:Int): Void
Ensures that the node in the specified row is collapsed.
If row
is < 0 or >= getRowCount
this
will have no effect.
row | an integer specifying a display row, where 0 is the first row in the display |
function expandPath(path:TreePath): Void
Ensures that the node identified by the specified path is expanded and viewable. If the last item in the path is a leaf, this will have no effect.
path | the |
function expandRow(row:Int): Void
Ensures that the node in the specified row is expanded and viewable.
If row
is < 0 or >= getRowCount
this
will have no effect.
row | an integer specifying a display row, where 0 is the first row in the display |
function fireTreeCollapsed(path:TreePath): Void
Notifies all listeners that have registered interest for
notification on this event type. The event instance
is lazily created using the path
parameter.
path | the |
function fireTreeExpanded(path:TreePath): Void
Notifies all listeners that have registered interest for
notification on this event type. The event instance
is lazily created using the path
parameter.
path | the |
function fireTreeWillCollapse(path:TreePath): Void
Notifies all listeners that have registered interest for
notification on this event type. The event instance
is lazily created using the path
parameter.
path | the |
function fireTreeWillExpand(path:TreePath): Void
Notifies all listeners that have registered interest for
notification on this event type. The event instance
is lazily created using the path
parameter.
path | the |
function getAnchorSelectionPath(): TreePath
Returns the path identified as the anchor.
returns | path identified as the anchor |
function getClosestPathForLocation(x:Int, y:Int): TreePath
Returns the path to the node that is closest to x,y. If
no nodes are currently viewable, or there is no model, returns
null
, otherwise it always returns a valid path. To test if
the node is exactly at x, y, get the node's bounds and
test x, y against that.
@see getPathForLocation @see getPathBounds
x | an integer giving the number of pixels horizontally from the left edge of the display area, minus any left margin |
y | an integer giving the number of pixels vertically from the top of the display area, minus any top margin |
returns | the |
function getClosestRowForLocation(x:Int, y:Int): Int
Returns the row to the node that is closest to x,y. If no nodes are viewable or there is no model, returns -1. Otherwise, it always returns a valid row. To test if the returned object is exactly at x, y, get the bounds for the node at the returned row and test x, y against that.
@see getRowForLocation @see getRowBounds
x | an integer giving the number of pixels horizontally from the left edge of the display area, minus any left margin |
y | an integer giving the number of pixels vertically from the top of the display area, minus any top margin |
returns | the row closest to the location, -1 if nothing is viewable or there is no model |
function getEditingPath(): TreePath
Returns the path to the element that is currently being edited.
returns | the |
function getExpandedDescendants(parent:TreePath): Array<Dynamic>
Returns an Array
of the descendants of the
path parent
that
are currently expanded. If parent
is not currently
expanded, this will return null
.
If you expand/collapse nodes while
iterating over the returned Array
this may not return all
the expanded paths, or may return paths that are no longer expanded.
parent | the path which is to be examined |
returns | an |
function getLastSelectedPathComponent(): Dynamic
Returns the last path component in the first node of the current selection.
@see TreePath.getLastPathComponent
returns | the last |
function getLeadSelectionPath(): TreePath
Returns the path identified as the lead.
returns | path identified as the lead |
function getLeadSelectionRow(): Int
Returns the row index corresponding to the lead path.
returns | an integer giving the row index of the lead path,
where 0 is the first row in the display; or -1
if |
function getLogicLocationFromPixelLocation(p:IntPoint): IntPoint
Returns the location in the JTree view area of the logic location.
function getMaxSelectionRow(): Int
Returns the last selected row.
returns | an integer designating the last selected row, where 0 is the first row in the display |
function getMinSelectionRow(): Int
Gets the first selected row.
returns | an integer designating the first selected row, where 0 is the first row in the display |
function getMousePointedPath(): TreePath
Returns the treePath that the user mouse pointed, null if no path was pointed.
returns | the path mouse pointed, null if not pointed any one. |
function getPathBounds(path:TreePath): IntRectangle
Returns the IntRectangle
that the specified node will be drawn
into. Returns null
if any component in the path is hidden
(under a collapsed parent).
Note:
This method returns a valid rectangle, even if the specified
node is not currently displayed.
path | the |
returns | the |
function getPathForLocation(x:Int, y:Int): TreePath
Returns the path for the node at the specified location.
x | an integer giving the number of pixels horizontally from the left edge of the display area, minus any left margin |
y | an integer giving the number of pixels vertically from the top of the display area, minus any top margin |
returns | the |
function getPathForRow(row:Int): TreePath
Returns the path for the specified row. If row
is
not visible, null
is returned.
row | an integer specifying a row |
returns | the |
function getPixelLocationFromLogicLocation(p:IntPoint): IntPoint
Returns the location in the JTree view area of the logic location.
function getRowBounds(row:Int): IntRectangle
Returns the IntRectangle
that the node at the specified row is
drawn in.
row | the row to be drawn, where 0 is the first row in the display |
returns | the |
function getRowCount(): Int
The number of rows that are currently being displayed.
returns | the number of rows that are being displayed |
function getRowForLocation(x:Int, y:Int): Int
Returns the row for the specified location.
@see getClosestRowForLocation
x | an integer giving the number of pixels horizontally from the left edge of the display area, minus any left margin |
y | an integer giving the number of pixels vertically from the top of the display area, minus any top margin |
returns | the row corresponding to the location, or -1 if the location is not within the bounds of a displayed cell |
function getRowForPath(path:TreePath): Int
Returns the row that displays the node identified by the specified path.
path | the |
returns | an integer specifying the display row, where 0 is the first row in the display, or -1 if any of the elements in path are hidden under a collapsed parent. |
function getSelectionCount(): Int
Returns the number of nodes selected.
returns | the number of nodes selected |
function getSelectionPath(): TreePath
Returns the path to the first selected node.
returns | the |
function getSelectionPaths(): Array<Dynamic>
Returns the paths of all selected values.
returns | an array of |
function getSelectionRow(): Int
Returns the first selected row. If nothing is selected -1 will be returned.
returns | the first selected row. If nothing is selected -1 will be returned. |
function getSelectionRows(): Array<Dynamic>
Returns all of the currently selected rows. This method is simply
forwarded to the TreeSelectionModel
.
If nothing is selected null
or an empty array will
be returned, based on the TreeSelectionModel
implementation.
returns | an array of integers that identifies all currently selected rows where 0 is the first row in the display |
Returns the L&F object that renders this component.
returns | the |
function hasBeenExpanded(path:TreePath): Bool
Returns true if the node identified by the path has ever been expanded.
returns | true if the |
function isCollapsed(path:TreePath): Bool
Returns true if the value identified by path is currently collapsed, this will return false if any of the values in path are currently not being displayed.
path | the |
returns | true if any of the nodes in the node's path are collapsed, false if all nodes in the path are expanded |
function isCollapsedOfRow(row:Int): Bool
Returns true if the node at the specified display row is collapsed.
row | the row to check, where 0 is the first row in the display |
returns | true if the node is currently collapsed, otherwise false |
Returns true if the tree is being edited. The item that is being
edited can be obtained using getSelectionPath
.
@see getSelectionPath
returns | true if the user is currently editing a node |
function isExpanded(path:TreePath): Bool
Returns true if the node identified by the path is currently expanded,
path | the |
returns | false if any of the nodes in the node's path are collapsed, true if all nodes in the path are expanded |
function isExpandedOfRow(row:Int): Bool
Returns true if the node at the specified display row is currently expanded.
row | the row to check, where 0 is the first row in the display |
returns | true if the node is currently expanded, otherwise false |
function isPathEditable(path:TreePath): Bool
This is invoked from the UI before editing begins to insure that the given path can be edited. This is provided as an entry point for subclassers to add filtered editing without having to resort to creating a new editor.
@see editable
returns | true if every parent node and the node itself is editable |
function isPathSelected(path:TreePath): Bool
Returns true if the item identified by the path is currently selected.
path | a |
returns | true if the node is selected |
function isPathVisible(path:TreePath): Bool
Returns true if the value identified by path is currently viewable, which means it is either the root or all of its parents are expanded. Otherwise, this method returns false.
returns | true if the node is viewable, otherwise false |
function isRowSelected(row:Int): Bool
Returns true if the node identified by row is selected.
row | an integer specifying a display row, where 0 is the first row in the display |
returns | true if the node is selected |
function isSelectionEmpty(): Bool
Returns true if the selection is currently empty.
returns | true if the selection is currently empty |
function makePathVisible(path:TreePath): Void
Ensures that the node identified by path is currently viewable.
path | the |
function removeDescendantSelectedPathsWithEvent(e:TreeModelEvent): Void
Removes any paths from the selection model that are descendants of
the nodes identified by in e
.
function removeSelectionInterval(index0:Int, index1:Int, ?programmatic:Bool = true): Void
Removes the nodes between index0 and index1, inclusive, from the selection.
index0 | an integer specifying a display row, where 0 is the first row in the display |
index1 | an integer specifying a second display row |
programmatic | indicate if this is a programmatic change |
function removeSelectionPath(path:TreePath, ?programmatic:Bool = true): Void
Removes the node identified by the specified path from the current selection.
path | the |
programmatic | indicate if this is a programmatic change |
function removeSelectionPaths(paths:Array<Dynamic>, ?programmatic:Bool = true): Void
Removes the nodes identified by the specified paths from the current selection.
paths | an array of |
programmatic | indicate if this is a programmatic change |
function removeSelectionRow(row:Int, ?programmatic:Bool = true): Void
Removes the row at the index row
from the current
selection.
row | the row to remove |
programmatic | indicate if this is a programmatic change |
function removeSelectionRows(rows:Array<Dynamic>, ?programmatic:Bool = true): Void
Removes the rows that are selected at each of the specified rows.
rows | an array of ints specifying display rows, where 0 is the first row in the display |
programmatic | indicate if this is a programmatic change |
function removeStateListener(listener:Dynamic ->Void): Void
Removes a state listener. @see org.aswing.event.AWEvent.STATE_CHANGED
listener | the listener to be removed. |
function scrollPathToVisible(path:TreePath): Void
Makes sure all the path components in path are expanded (except
for the last path component) and scrolls so that the
node identified by the path is displayed. Only works when this
JTree
is contained in a JScrollPane
.
path | the |
function scrollRowToVisible(row:Int): Void
Scrolls the item identified by row until it is displayed. The minimum
of amount of scrolling necessary to bring the row into view
is performed. Only works when this JTree
is contained in a
JScrollPane
.
row | an integer specifying the row to scroll, where 0 is the first row in the display |
function setAnchorSelectionPath(newPath:TreePath): Void
Sets the path identified as the anchor.
The anchor is not maintained by JTree
, rather the UI will
update it.
newPath | the new anchor path |
function setLeadSelectionPath(newPath:TreePath): Void
Sets the path identifies as the lead. The lead may not be selected.
The lead is not maintained by JTree
,
rather the UI will update it.
newPath | the new lead path |
function setSelectionInterval(index0:Int, index1:Int, ?programmatic:Bool = true): Void
Selects the nodes between index0 and index1, inclusive.
index0 | an integer specifying a display row, where 0 is the first row in the display |
index1 | an integer specifying a second display row |
programmatic | indicate if this is a programmatic change |
function setSelectionMode(mode:Int): Void
Proxy method which passes specified selection mode to the currently configured selection model.
mode | the selection mode identifier |
function setSelectionPath(path:TreePath, ?programmatic:Bool = true): Void
Selects the node identified by the specified path. If any
component of the path is hidden (under a collapsed node), and
getExpandsSelectedPaths
is true it is
exposed (made viewable).
path | the |
programmatic | indicate if this is a programmatic change |
function setSelectionPaths(paths:Array<Dynamic>, ?programmatic:Bool = true): Void
Selects the nodes identified by the specified array of paths.
If any component in any of the paths is hidden (under a collapsed
node), and getExpandsSelectedPaths
is true
it is exposed (made viewable).
paths | an array of |
programmatic | indicate if this is a programmatic change |
function setSelectionRow(row:Int, ?programmatic:Bool = true): Void
Selects the node at the specified row in the display.
row | the row to select, where 0 is the first row in the display |
programmatic | indicate if this is a programmatic change |
function setSelectionRows(rows:Array<Dynamic>, ?programmatic:Bool = true): Void
Selects the nodes corresponding to each of the specified rows
in the display. If a particular element of rows
is
< 0 or >= getRowCount
, it will be ignored.
If none of the elements
in rows
are valid rows, the selection will
be cleared. That is it will be as if clearSelection
was invoked.
rows | an array of ints specifying the rows to select, where 0 indicates the first row in the display |
programmatic | indicate if this is a programmatic change |
function startEditingAtPath(path:TreePath): Void
Selects the node identified by the specified path and initiates
editing. The edit-attempt fails if the CellEditor
does not allow
editing for the specified item.
path | the |
function stopEditing(): Bool
Ends the current editing session.
(The DefaultTreeCellEditor
object saves any edits that are currently in progress on a cell.
Other implementations may operate differently.)
Has no effect if the tree isn't being edited.
Note:
To make edit-saves automatic whenever the user changes their position in the tree, use {@linksetInvokesStopCellEditing}.
returns | true if editing was in progress and is now stopped, false if editing was not in progress |
function treeDidChange(): Void
Notifies all listeners that have registered interest for notification on this event type.
e | the
when a node is selected or deselected See EventListenerList |