Packageorg.aswing
Classpublic class JTree
InheritanceJTree Inheritance Container Inheritance Component Inheritance AWSprite Inheritance flash.display.Sprite
ImplementsCellEditorListener, TreeModelListener, Viewportable

A control that displays a set of hierarchical data as an outline. A control that displays a set of hierarchical data as an outline. You can find task-oriented documentation and examples of using trees in How to Use Trees, a section in The Java Tutorial.

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":

The next group of JTree methods use "visible" to mean "viewable" (under an expanded parent):

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.MOUSE_DOWN, __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 {

See also

TreeModel


Public Properties
 PropertyDefined by
 InheritedcacheAsBitmap : Boolean
AWSprite
 Inheritedcontainer : Container
Component
 Inheritedfilters : Array
AWSprite
 Inheritedheight : Number
Component
 Inheritedmask : DisplayObject
AWSprite
 InheritednumChildren : int
AWSprite
 Inheritedvisible : Boolean
Component
 Inheritedwidth : Number
Component
 Inheritedx : Number
Component
 Inheritedy : Number
Component
Protected Properties
 PropertyDefined by
 Inheritedbounds : IntRectangle
Component
 Inheritedchildren : Array
Container
 Inheritedd_numChildren : int
AWSprite
 InheriteddrawTransparentTrigger : Boolean = true
Component
 Inheritedd_visible : Boolean
Returns the DisplayObject.visible directly.
Component
 Inheritedd_x : Number
Returns DisplayObject.x directly.
Component
 Inheritedd_y : Number
Returns DisplayObject.y directly.
Component
 Inheritedlayout : LayoutManager
Container
 InheritedreadyToPaint : Boolean
Component
 Inheritedui : ComponentUI
Component
 Inheritedvalid : Boolean
Component
Public Methods
 MethodDefined by
  
JTree(newModel:TreeModel = null)
JTree(newModel:TreeModel)
; JTree() a defaul model will be created
Returns an instance of JTree which displays the root node -- the tree is created using the specified data model.
JTree
 Inherited
addChild(dis:DisplayObject):DisplayObject
Adds a child DisplayObject instance to this DisplayObjectContainer instance.
AWSprite
 Inherited
addChildAt(child:DisplayObject, index:int):DisplayObject
AWSprite
 Inherited
Adds a component to be the acceptable drag initiator to this component.
Component
  
addSelectionInterval(index0:int, index1:int, programmatic:Boolean = true):void
Adds the paths between index0 and index1, inclusive, to the selection.
JTree
  
addSelectionListener(listener:Function, priority:int = 0, useWeakReference:Boolean = false):void
Adds a listener for tree selection events.
JTree
  
addSelectionPath(path:TreePath, programmatic:Boolean = true):void
Adds the node identified by the specified TreePath to the current selection.
JTree
  
addSelectionPaths(paths:Array, programmatic:Boolean = true):void
Adds each path in the array of paths to the current selection.
JTree
  
addSelectionRow(row:int, programmatic:Boolean = true):void
Adds the path at the specified row to the current selection.
JTree
  
addSelectionRows(rows:Array, programmatic:Boolean = true):void
Adds the paths at each of the specified rows to the current selection.
JTree
  
addStateListener(listener:Function, priority:int = 0, useWeakReference:Boolean = false):void
Add a listener to listen the viewpoat state change event.
JTree
 Inherited
append(com:Component, constraints:Object = null):void
On Component just can add to one Container.
Container
 Inherited
appendAll(... coms):void
Adds one or more component to the container with null constraints
Container
 Inherited
bringToBottom(child:DisplayObject):void
Brings a child to bottom.
AWSprite
 Inherited
bringToTop(child:DisplayObject):void
Brings a child to top.
AWSprite
  
Cancels the current editing session.
JTree
  
clearSelection(programmatic:Boolean = true):void
Clears the selection.
JTree
  
Ensures that the node identified by the specified path is collapsed and viewable.
JTree
  
collapseRow(row:int):void
Ensures that the node in the specified row is collapsed.
JTree
 Inherited
Component
 Inherited
containsChild(child:DisplayObject):Boolean
Returns whether child is directly child of this sprite, true only if getChildIndex(child) >= 0.
AWSprite
 Inherited
doLayout():void
layout this container
Container
  
JTree
  
JTree
  
expandPath(path:TreePath):void
Ensures that the node identified by the specified path is expanded and viewable.
JTree
  
expandRow(row:int):void
Ensures that the node in the specified row is expanded and viewable.
JTree
 Inherited
fireFocusKeyDownEvent(e:KeyboardEvent):void
Component
 Inherited
fireFocusKeyUpEvent(e:KeyboardEvent):void
Component
  
Notifies all listeners that have registered interest for notification on this event type.
JTree
  
Notifies all listeners that have registered interest for notification on this event type.
JTree
  
Notifies all listeners that have registered interest for notification on this event type.
JTree
  
Notifies all listeners that have registered interest for notification on this event type.
JTree
 Inherited
getAlignmentX():Number
Returns the alignment along the x axis.
Component
 Inherited
getAlignmentY():Number
Returns the alignment along the y axis.
Component
 Inherited
getAlpha():Number
Returns the alpha of this component.
Component
  
Returns the path identified as the anchor.
JTree
 Inherited
getAwmlID():String
Returns ID used to identify components created from AWML.
Component
 Inherited
getAwmlIndex():Number
Returns position index of the component inside its AWML container.
Component
 Inherited
Returns namespace name used to identify components created from AWML.
Component
 Inherited
Gets the background color of this component.
Component
 Inherited
Returns the background decorator of this component.
Component
 Inherited
Returns the border.
Component
 Inherited
getBounds(targetCoordinateSpace:DisplayObject):Rectangle
Same to DisplayObject.getBounds(), just add a explaination here that if you want to get the component bounds, see {
Component
  
Returns the editor used to edit entries in the tree.
JTree
  
Returns the current TreeCellFactory that is rendering each cell.
JTree
 Inherited
getChildAt(index:int):DisplayObject
AWSprite
 Inherited
getChildByName(name:String):DisplayObject
AWSprite
 Inherited
getChildIndex(child:DisplayObject):int
AWSprite
 Inherited
Returns the value of the property with the specified key.
Component
 Inherited
Returns the clip bounds.
Component
  
Returns the path to the node that is closest to x,y.
JTree
  
getClosestRowForLocation(x:int, y:int):int
Returns the row to the node that is closest to x,y.
JTree
 Inherited

Stores the bounds value of this component into "return value" rv and returns rv.

Component
 Inherited
getComponent(index:int):Component
Gets the nth(index) component in this container.
Container
 Inherited
Gets the number of components in this container.
Container
 Inherited
getConstraints():Object
Gets cpmponent's constraints.
Component
  
JTree
  
Returns the path to the element that is currently being edited.
JTree
  
Returns an Array of the descendants of the path parent that are currently expanded.
JTree
  
JTree
  
Returns the fixed cell width value -- the value specified by setting the fixedCellWidth property, rather than that calculated from the cell elements.
JTree
 Inherited
Returns the focus manager for this component's stage, or null if this component is not on stage.
Component
 Inherited
Returns the focus traversal policy of this container, it will return its parent's focus traversal policy if its self is null.
Container
 Inherited
Gets the font of this component.
Component
 Inherited
Gets the foreground color of this component.
Component
 Inherited
Returns the foreground decorator of this component.
Component
 Inherited
Stores the global location value of this component into "return value" p and returns p.
Component
 Inherited
getHeight():int
Returns the current height of this component
Component
 Inherited
Returns the current top index for a new child(none forground child).
AWSprite
  
JTree
  
JTree
 Inherited
Returns the index of the child component in this container.
Container
 Inherited
If a border has been set on this component, returns the border's insets; otherwise returns an empty insets.
Component
 Inherited
getInternalFocusObject():InteractiveObject
Returns the object to receive the focus for this component.
Component
 Inherited
Returns the keyboard manager of this component's JRootPane ancestor.
Component
  
Returns the last path component in the first node of the current selection.
JTree
 Inherited
Container
  
Returns the path identified as the lead.
JTree
  
Returns the row index corresponding to the lead path.
JTree
 Inherited
Stores the location value of this component into "return value" rv and returns rv.
Component
  
Returns the location in the JTree view area of the logic location.
JTree
 Inherited
Returns the current bottom index for none background child.
AWSprite
 Inherited
Returns getMaximumSize().height
Component
 Inherited
Component
 Inherited
Returns getMaximumSize().width
Component
  
Returns the last selected row.
JTree
 Inherited
Returns getMinimumSize().height
Component
 Inherited
Component
 Inherited
Returns getMinimumSize().width
Component
  
Gets the first selected row.
JTree
  
Returns the TreeModel that is providing the data.
JTree
  
Returns the treePath that the user mouse pointed, null if no path was pointed.
JTree
 Inherited
Returns the coordinate of the mouse position, in pixels, in the component scope.
Component
 Inherited
getName():String
Returns the name of the component
Component
 Inherited
Returns the bounds that component should paint in.
Component
 Inherited
Returns the Container parent, if it parent is not a Container, null will be returned.
Component
  
Returns the IntRectangle that the specified node will be drawn into.
JTree
  
Returns the path for the node at the specified location.
JTree
  
Returns the path for the specified row.
JTree
  
Returns the location in the JTree view area of the logic location.
JTree
 Inherited
Returns getPreferredSize().height
Component
 Inherited
Component
 Inherited
Returns getPreferredSize().width
Component
 Inherited
Returns the first JRootPane ancestor of this component.
Component
  
Returns the IntRectangle that the node at the specified row is drawn in.
JTree
  
Returns the number of rows that are currently being displayed.
JTree
  
getRowForLocation(x:int, y:int):int
Returns the row for the specified location.
JTree
  
Returns the row that displays the node identified by the specified path.
JTree
  
Returns the height of each row.
JTree
  
Returns the background color for selected cells.
JTree
  
Returns the number of nodes selected.
JTree
  
Returns the foreground color for selected cells.
JTree
  
Returns the model for selections.
JTree
  
Returns the path to the first selected node.
JTree
  
Returns the paths of all selected values.
JTree
  
Returns the first selected row.
JTree
  
Returns all of the currently selected rows.
JTree
 Inherited
Stores the size value of this component into "return value" rv and returns rv.
Component
  
Returns the number of mouse clicks needed to expand or close a node.
JTree
 Inherited
getToolTipText():String
Returns the tooltip string that has been set with setToolTipText.
Component
  
getTreeUI():TreeUI
Returns the L&F object that renders this component.
JTree
 Inherited
Component
  
getUIClassID():String
Returns the name of the L&F class that renders this component.
JTree
  
JTree
  
JTree
  
JTree
  
JTree
  
JTree
  
JTree
  
Returns the number of rows that are displayed in the display area.
JTree
 Inherited
getWidth():int
Returns the current width of this component
Component
 Inherited
getX():int
Returns the current x coordinate of the components.
Component
 Inherited
getY():int
Returns the current y coordinate of the components.
Component
 Inherited
Component
  
hasBeenExpanded(path:TreePath):Boolean
Returns true if the node identified by the path has ever been expanded.
JTree
 Inherited
hitTestMouse():Boolean
Returns whether the component hit the mouse.
Component
 Inherited
hitTestObject(obj:DisplayObject):Boolean
AWSprite
 Inherited
hitTestPoint(x:Number, y:Number, shapeFlag:Boolean = false):Boolean
AWSprite
 Inherited
insert(i:int, com:Component, constraints:Object = null):void
Add component to spesified index.
Container
 Inherited
insertAll(index:int, ... coms):void
Insets one or more component to the container with null constraints at specified starting index.
Container
 Inherited
invalidate():void
Invalidates the container.
Container
 Inherited
Clears this component and all parents above it's preferred size caches.
Component
 Inherited
Checks if the component is contained in the component hierarchy of this container.
Container
 Inherited
Returns whether or not the preferred size, minimum size and max size cache is turned on.
Component
 Inherited
isClipMasked():Boolean
Returns whether the component clip should be masked by its bounds.
AWSprite
  
isCollapsed(path:TreePath):Boolean
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.
JTree
  
isCollapsedOfRow(row:int):Boolean
Returns true if the node at the specified display row is collapsed.
JTree
 Inherited
Returns whether the component is acceptable drag initiator for this component.
Component
 Inherited
isDragEnabled():Boolean
Returns whether this component can fire ON_DRAG_RECOGNIZED event.
Component
 Inherited
isDropTrigger():Boolean
Returns whether this component can trigger dragging component to fire drag events when dragging over to this component.(Default value is false)
Component
  
isEditable():Boolean
Returns true if the tree is editable.
JTree
  
isEditing():Boolean
Returns true if the tree is being edited.
JTree
 Inherited
isEnabled():Boolean
Returns whether the component is enabled.
Component
  
isExpanded(path:TreePath):Boolean
Returns true if the node identified by the path is currently expanded,
JTree
  
isExpandedOfRow(row:int):Boolean
Returns true if the node at the specified display row is currently expanded.
JTree
  
Returns the expandsSelectedPaths property.
JTree
 Inherited
isFocusable():Boolean
Returns whether this Component can be focused.
Component
 Inherited
isFocusableSet():Boolean
Returns whether or not the opaque property is set by user.
Component
 Inherited
isFocusOwner():Boolean
Returns true if this Component is the focus owner.
Component
 Inherited
isFontValidated():Boolean
Returns whether the new font are applied and taked effect.
Component
  
Returns the indicator that tells what happens when editing is interrupted.
JTree
 Inherited
isOnStage():Boolean
Determines whether or not this component is on stage(on the display list).
Component
 Inherited
isOpaque():Boolean
Returns true if this component is completely opaque.
Component
 Inherited
isOpaqueSet():Boolean
Returns whether or not the opaque property is set by user.
Component
  
isPathEditable(path:TreePath):Boolean
Returns isEditable.
JTree
  
isPathSelected(path:TreePath):Boolean
Returns true if the item identified by the path is currently selected.
JTree
  
isPathVisible(path:TreePath):Boolean
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.
JTree
  
isRootVisible():Boolean
Returns true if the root node of the tree is displayed.
JTree
  
isRowHeightSet():Boolean
Returns whether or not row height is set by user.
JTree
  
isRowSelected(row:int):Boolean
Returns true if the node identified by row is selected.
JTree
  
Returns the value of the scrollsOnExpand property.
JTree
  
Returns whether or not scrolls on expand is set by user.
JTree
  
isSelectionEmpty():Boolean
Returns true if the selection is currently empty.
JTree
 Inherited
isShowing():Boolean
Determines whether this component is showing on screen.
Component
 Inherited
isUIElement():Boolean
Returns true if this component is just a ui element component, false means this component is a regular use created component.
Component
 Inherited
isValid():Boolean
Determines whether this component is valid.
Component
 Inherited
isValidateRoot():Boolean
If this method returns true, revalidate calls by descendants of this component will cause the entire tree beginning with this root to be validated.
Component
 Inherited
isVisible():Boolean
Component
 Inherited
makeFocus():void
Makes this component's internal focus object to be the stage focus directly, without any judgement.
Component
  
Ensures that the node identified by path is currently viewable.
JTree
 Inherited
pack():void
Causes this component to be sized to fit the preferred size.
Component
 Inherited
paintFocusRect(force:Boolean = false):void
Paints the focus rect if need.
Component
 Inherited
Redraw the component UI face immediately if it is visible and ready to paint.
Component
 Inherited
Calls parent reAppendChildren if parent is a container.
Component
 Inherited
putClientProperty(key:*, value:*):void
Adds an arbitrary key/value "client property" to this component.
Component
 Inherited
Removes all children and then append them with their constraints.
Container
 Inherited
reAppendToParent(constraints:Object = null):void
Removes this component from its parent and then append it with specified constraints.
Component
 Inherited
Remove the specified child component.
Container
 Inherited
removeAll():void
Remove all child components.
Container
 Inherited
Remove the specified index child component.
Container
 Inherited
removeChild(child:DisplayObject):DisplayObject
Removes a normal display object child.
Container
 Inherited
removeChildAt(index:int):DisplayObject
Removes a normal display object child with index.
Container
  
Removes any paths from the selection model that are descendants of the nodes identified by in e.
JTree
 Inherited
Removes a component to be the acceptable drag initiator to this component.
Component
 Inherited
Removes this component from its parent, whatever it is as a component child or only a display object child, or it's parent is just a display object container.
Component
  
removeSelectionInterval(index0:int, index1:int, programmatic:Boolean = true):void
Removes the nodes between index0 and index1, inclusive, from the selection.
JTree
  
removeSelectionListener(listener:Function):void
JTree
  
removeSelectionPath(path:TreePath, programmatic:Boolean = true):void
Removes the node identified by the specified path from the current selection.
JTree
  
removeSelectionPaths(paths:Array, programmatic:Boolean = true):void
Removes the nodes identified by the specified paths from the current selection.
JTree
  
removeSelectionRow(row:int, programmatic:Boolean = true):void
Removes the row at the index row from the current selection.
JTree
  
removeSelectionRows(rows:Array, programmatic:Boolean = true):void
Removes the rows that are selected at each of the specified rows.
JTree