All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class com.sun.java.swing.JTree

java.lang.Object
   |
   +----java.awt.Component
           |
           +----java.awt.Container
                   |
                   +----com.sun.java.swing.JComponent
                           |
                           +----com.sun.java.swing.JTree

public class JTree
extends JComponent
A control that displays a set of hierarchical data as an outline. Posts changes for the following names: cellRenderer, treeModel, rootVisible, showsRootHandles, rowHeight, cellEditor, editable


Variable Index

 o cellEditor
Editor for the entries.
 o cellRenderer
The cell used to draw nodes.
 o editable
Is the tree editable?
 o expansionListener
Multicaster for expansion events.
 o rootVisible
True if the root node is displayed, false if its children are the highest visible nodes.
 o rowHeight
Height to use for each row.
 o selectionListener
Multicaster for tree selection events.
 o selectionModel
Models the set of selected nodes in this tree.
 o selectionRedirector
Creates a new event and passed it off the selectionListeners.
 o showsRootHandles
true if there should be handles at the top level.
 o treeModel
The model that defines the tree displayed by this object.

Constructor Index

 o JTree()
Returns a JTree with no data model.
 o JTree(TreeModel)
Returns an instance of JTree using the TreeModel newModel.
 o JTree(TreeNode)
Returns a JTree with an instance of JTreeModel as its data model, rooted at root and asksAllowsChildren false.
 o JTree(TreeNode, boolean)
Returns a JTree with an instance of JTreeModel as its data model.

Method Index

 o addSelectionInterval(int, int)
Adds the paths between index0 and index1 to the selection.
 o addSelectionPath(JTreePath)
Adds the path identified by path to the current selection.
 o addSelectionPaths(JTreePath[])
Adds each path in paths to the current selection.
 o addSelectionRow(int)
Adds the path at row to the current selection.
 o addSelectionRows(int[])
Adds the paths at each of the rows in rows to the current selection.
 o addTreeExpansionListener(TreeExpansionListener)
Adds tel as interested in recieving TreeExpansion events.
 o addTreeSelectionListener(TreeSelectionListener)
Adds tsl as interested in recieving TreeSelection events.
 o clearSelection()
Clears the selection.
 o collapsePath(JTreePath)
Insures that the last item identified in path is collapsed and visible.
 o collapseRow(int)
Insures that the item identified by row is collapsed.
 o expandPath(JTreePath)
Insures that the last item identified in path is expanded and visible.
 o expandRow(int)
Insures that the item identified by row is expanded.
 o getCellEditor()
Returns the editor used to edit entries in the tree.
 o getCellRenderer()
Returns the current TreeCellRenderer that is rendering each cell.
 o getClosestPathForLocation(int, int)
Returns the path to the node that is closest to x,y.
 o getClosestRowForLocation(int, int)
Returns the row to the node that is closest to x,y.
 o getEditingPath()
Returns the path to the element that is being edited.
 o getMaxSelectionRow()
Gets the last selected row.
 o getMinSelectionRow()
Gets the first selected row.
 o getModel()
Returns the TreeModel that is providing the data.
 o getPathBetweenRows(int, int)
Returns JTreePath instances representing the path between index0 and index1 (including index1).
 o getPathBounds(JTreePath)
Returns the Rectangle that the last item in path will be drawn into.
 o getPathForRow(int)
Returns the path for passed in row.
 o getRowBounds(int)
Returns the Rectangle that the item identified by row will be drawn into.
 o getRowCount()
Returns the number of rows that are currently being displayed.
 o getRowForPath(JTreePath)
Returns the row that the last item identified in path is visible at.
 o getRowHeight()
Returns the height of each row.
 o getSelectionModel()
Returns the model for selections.
 o getSelectionPath()
Returns the path to the first selected value, or null if nothing is currently selected.
 o getSelectionPaths()
Returns the path of the selected values, or null if nothing is current selected.
 o getSelectionRows()
Returns all of the currently selected rows.
 o getShowsRootHandles()
Returns true if handles for the root nodes are displayed.
 o getTreeExpansionListener()
Returns the multicaster for TreeExpansionEvents.
 o getTreeSelectionListener()
Returns the multicaster for TreeSelectionEvents.
 o getUI()
Returns the TreeUI that is providing the current look and feel.
 o isCollapsed(int)
Returns true if the value identified by row is currently collapsed.
 o isCollapsed(JTreePath)
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.
 o isEditable()
Returns true if the tree is editable.
 o isEditing()
Returns true if the tree is being edited.
 o isExpanded(int)
Returns true if the value identified by row is currently expanded.
 o isExpanded(JTreePath)
Returns true if the value identified by path is currently expanded, this will return false if any of the values in path are currently not being displayed.
 o isFixedRowHeight()
Returns true if the height of each row is a fixed size.
 o isOpaque()
 o isPathSelected(JTreePath)
Returns true if item identified by path is currently selected.
 o isRootVisible()
Returns true if the root node from the TreeModel is currently visible.
 o isRowSelected(int)
Returns true if the row identitifed by row is selected.
 o isSelectionEmpty()
Returns true if the selection is currently empty.
 o isVisible(JTreePath)
Returns true if the value identified by path is currently visible, false otherwise.
 o makeVisible(JTreePath)
Insures that the value identified by path is currently visible.
 o removeSelectionInterval(int, int)
Removes the paths between index0 and index1 from the selection.
 o removeTreeExpansionListener(TreeExpansionListener)
Removes tel as being interested in recieving TreeExpansion events.
 o removeTreeSelectionListener(TreeSelectionListener)
Removes tsl as being interested in recieving TreeSelection events.
 o scrollPathToVisible(JTreePath)
Makes sure all the path components in path are expanded (accept for the last path component) and tries to scroll the resulting path to be visible.
 o scrollRowToVisible(int)
Scrolls the item identified by row to be visible.
 o setCellEditor(TreeCellEditor)
Sets the cell editor to cellEditor.
 o setCellRenderer(TreeCellRenderer)
Sets the TreeCellRenderer that will be used to draw each cell.
 o setEditable(boolean)
Sets the tree to being editable based on flag.
 o setModel(TreeModel)
Sets the TreeModel that will provide the data.
 o setRootVisible(boolean)
Sets, based on rootVisible, whether or not the root node from the TreeModel is visible.
 o setRowHeight(int)
Sets the height of each to be rowHeight.
 o setSelectionInterval(int, int)
Sets the selection to the paths of the nodes between index0 and index1.
 o setSelectionPath(JTreePath)
Sets to selection to the value identified by path.
 o setSelectionPaths(JTreePath[])
Sets the selection to paths.
 o setSelectionRow(int)
The current selection is set to the path for the item at row.
 o setSelectionRows(int[])
The selection is set to the paths for the items at each of the rows in rows.
 o setShowsRootHandles(boolean)
Sets whether or not the root handles are to be displayed.
 o setUI(TreeUI)
Sets the TreeUI that will provide the current look and feel.
 o startEditingAtPath(JTreePath)
Selects the last item in path and tries to edit it.
 o stopEditing()
Stops the current editing session.
 o treeDidChange()
Sent when the tree has changed enough that we need to resize the bounds, but not enough that we need to remove the expanded node set (e.g nodes were expanded or collapsed, or nodes were inserted into the tree)
 o updateUI()
Called to replace the UI with the latest version from the default UIFactory.

Variables

 o treeModel
 protected TreeModel treeModel
The model that defines the tree displayed by this object.

 o selectionModel
 protected JTreeSelectionModel selectionModel
Models the set of selected nodes in this tree.

 o rootVisible
 protected boolean rootVisible
True if the root node is displayed, false if its children are the highest visible nodes.

 o cellRenderer
 protected TreeCellRenderer cellRenderer
The cell used to draw nodes. If null, the UI uses a default cellRenderer.

 o rowHeight
 protected int rowHeight
Height to use for each row. If this is <= 0 the renderer will be used to determine the height for each row.

 o showsRootHandles
 protected boolean showsRootHandles
true if there should be handles at the top level. If the root isn't visible it is highly recommended to make this true.

 o expansionListener
 protected TreeExpansionListener expansionListener
Multicaster for expansion events.

 o selectionListener
 protected TreeSelectionListener selectionListener
Multicaster for tree selection events.

 o selectionRedirector
 protected JTree. TreeSelectionRedirector selectionRedirector
Creates a new event and passed it off the selectionListeners.

 o cellEditor
 protected TreeCellEditor cellEditor
Editor for the entries.

 o editable
 protected boolean editable
Is the tree editable?

Constructors

 o JTree
 public JTree()
Returns a JTree with no data model.

 o JTree
 public JTree(TreeNode root)
Returns a JTree with an instance of JTreeModel as its data model, rooted at root and asksAllowsChildren false.

 o JTree
 public JTree(TreeNode root,
              boolean asksAllowsChildren)
Returns a JTree with an instance of JTreeModel as its data model. asksAllowsChildren is passed into the constructore of JTreeModel which will determine how JTreeModel tests for leafness. If asksAllowsChildren is true leafness is determined by messaging getAllowsChildren, otherwise isLeaf is messaged.

 o JTree
 public JTree(TreeModel newModel)
Returns an instance of JTree using the TreeModel newModel.

Methods

 o getUI
 public TreeUI getUI()
Returns the TreeUI that is providing the current look and feel.

 o setUI
 public void setUI(TreeUI ui)
Sets the TreeUI that will provide the current look and feel.

 o updateUI
 public void updateUI()
Called to replace the UI with the latest version from the default UIFactory.

Overrides:
updateUI in class JComponent
 o getCellRenderer
 public TreeCellRenderer getCellRenderer()
Returns the current TreeCellRenderer that is rendering each cell.

 o setCellRenderer
 public void setCellRenderer(TreeCellRenderer x)
Sets the TreeCellRenderer that will be used to draw each cell.

 o setEditable
 public void setEditable(boolean flag)
Sets the tree to being editable based on flag. Fires a property change if flag is different that the current editability.

 o isEditable
 public boolean isEditable()
Returns true if the tree is editable.

 o setCellEditor
 public void setCellEditor(TreeCellEditor cellEditor)
Sets the cell editor to cellEditor. A null value implies that the tree can not be edited. If this signifies a change in the cellEditor and propertyChange method is invoked on all the listeners.

 o getCellEditor
 public TreeCellEditor getCellEditor()
Returns the editor used to edit entries in the tree. Null implies the tree can not be edited.

 o getModel
 public TreeModel getModel()
Returns the TreeModel that is providing the data.

 o setModel
 public void setModel(TreeModel newModel)
Sets the TreeModel that will provide the data.

 o isRootVisible
 public boolean isRootVisible()
Returns true if the root node from the TreeModel is currently visible.

 o setRootVisible
 public void setRootVisible(boolean rootVisible)
Sets, based on rootVisible, whether or not the root node from the TreeModel is visible.

 o setShowsRootHandles
 public void setShowsRootHandles(boolean newValue)
Sets whether or not the root handles are to be displayed.

 o getShowsRootHandles
 public boolean getShowsRootHandles()
Returns true if handles for the root nodes are displayed.

 o setRowHeight
 public void setRowHeight(int rowHeight)
Sets the height of each to be rowHeight. If rowHeight is less than or equal to zero the current cell renderer will be queried for each rows height.

 o getRowHeight
 public int getRowHeight()
Returns the height of each row. If returned value is less than or equal to 0 the height for each row is determined by the renderer.

 o isFixedRowHeight
 public boolean isFixedRowHeight()
Returns true if the height of each row is a fixed size.

 o getRowCount
 public int getRowCount()
Returns the number of rows that are currently being displayed.

 o setSelectionPath
 public void setSelectionPath(JTreePath path)
Sets to selection to the value identified by path. If any component of path is not currently visible it will be made visible.

 o setSelectionPaths
 public void setSelectionPaths(JTreePath paths[])
Sets the selection to paths. If any component in any of the paths is not currently visible it will be made visible.

 o setSelectionRow
 public void setSelectionRow(int row)
The current selection is set to the path for the item at row.

 o setSelectionRows
 public void setSelectionRows(int rows[])
The selection is set to the paths for the items at each of the rows in rows.

 o addSelectionPath
 public void addSelectionPath(JTreePath path)
Adds the path identified by path to the current selection. If any component of path isn't visible, it will be made visible.

 o addSelectionPaths
 public void addSelectionPaths(JTreePath paths[])
Adds each path in paths to the current selection. If any component of any of the paths isn't visible, it will be made visible.

 o addSelectionRow
 public void addSelectionRow(int row)
Adds the path at row to the current selection.

 o addSelectionRows
 public void addSelectionRows(int rows[])
Adds the paths at each of the rows in rows to the current selection.

 o getSelectionPath
 public JTreePath getSelectionPath()
Returns the path to the first selected value, or null if nothing is currently selected.

 o getSelectionPaths
 public JTreePath[] getSelectionPaths()
Returns the path of the selected values, or null if nothing is current selected.

 o getSelectionRows
 public int[] getSelectionRows()
Returns all of the currently selected rows.

 o getMinSelectionRow
 public int getMinSelectionRow()
Gets the first selected row.

 o getMaxSelectionRow
 public int getMaxSelectionRow()
Gets the last selected row.

 o isPathSelected
 public boolean isPathSelected(JTreePath path)
Returns true if item identified by path is currently selected.

 o isRowSelected
 public boolean isRowSelected(int row)
Returns true if the row identitifed by row is selected.

 o isExpanded
 public boolean isExpanded(JTreePath path)
Returns true if the value identified by path is currently expanded, this will return false if any of the values in path are currently not being displayed.

 o isExpanded
 public boolean isExpanded(int row)
Returns true if the value identified by row is currently expanded.

 o isCollapsed
 public boolean isCollapsed(JTreePath path)
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.

 o isCollapsed
 public boolean isCollapsed(int row)
Returns true if the value identified by row is currently collapsed.

 o makeVisible
 public void makeVisible(JTreePath path)
Insures that the value identified by path is currently visible.

 o isVisible
 public boolean isVisible(JTreePath path)
Returns true if the value identified by path is currently visible, false otherwise.

 o getPathBounds
 public Rectangle getPathBounds(JTreePath path)
Returns the Rectangle that the last item in path will be drawn into. Will return null if any component in path is currently valid.

 o getRowBounds
 public Rectangle getRowBounds(int row)
Returns the Rectangle that the item identified by row will be drawn into. Will return null if any component in path is currently valid.

 o scrollPathToVisible
 public void scrollPathToVisible(JTreePath path)
Makes sure all the path components in path are expanded (accept for the last path component) and tries to scroll the resulting path to be visible.

 o scrollRowToVisible
 public void scrollRowToVisible(int row)
Scrolls the item identified by row to be visible. This will only work if the JTree is contained in a JSrollPane.

 o getPathForRow
 public JTreePath getPathForRow(int row)
Returns the path for passed in row. If row is not visible null is returned.

 o getRowForPath
 public int getRowForPath(JTreePath path)
Returns the row that the last item identified in path is visible at. Will return -1 if any of the elements in path are not currently visible.

 o expandPath
 public void expandPath(JTreePath path)
Insures that the last item identified in path is expanded and visible.

 o expandRow
 public void expandRow(int row)
Insures that the item identified by row is expanded.

 o collapsePath
 public void collapsePath(JTreePath path)
Insures that the last item identified in path is collapsed and visible.

 o collapseRow
 public void collapseRow(int row)
Insures that the item identified by row is collapsed.

 o getClosestPathForLocation
 public JTreePath getClosestPathForLocation(int x,
                                            int y)
Returns the path to the node that is closest to x,y. If there is nothing currently visible, or no model, this will return null, otherwise it'll always return a valid path. If you need to test if the returned object is exactly at x, y you should get the bounds for the returned path and test x, y against that.

 o getClosestRowForLocation
 public int getClosestRowForLocation(int x,
                                     int y)
Returns the row to the node that is closest to x,y. If there is nothing currently visible this will return -1, otherwise it'll always return a valid row. If you need to test if the returned object is exactly at x, y you should get the bounds for the returned row and test x, y against that.

 o isEditing
 public boolean isEditing()
Returns true if the tree is being edited. The item that is being edited can be returned by getSelectionPath().

 o stopEditing
 public boolean stopEditing()
Stops the current editing session. This has no effect if the tree isn't being edited.

 o startEditingAtPath
 public void startEditingAtPath(JTreePath path)
Selects the last item in path and tries to edit it. Editing will fail if the CellEditor won't allow it for the selected item.

 o getEditingPath
 public JTreePath getEditingPath()
Returns the path to the element that is being edited.

 o getSelectionModel
 public TreeSelectionModel getSelectionModel()
Returns the model for selections.

 o getPathBetweenRows
 protected JTreePath[] getPathBetweenRows(int index0,
                                          int index1)
Returns JTreePath instances representing the path between index0 and index1 (including index1). Will return null if there is no tree.

 o setSelectionInterval
 public void setSelectionInterval(int index0,
                                  int index1)
Sets the selection to the paths of the nodes between index0 and index1.

 o addSelectionInterval
 public void addSelectionInterval(int index0,
                                  int index1)
Adds the paths between index0 and index1 to the selection.

 o removeSelectionInterval
 public void removeSelectionInterval(int index0,
                                     int index1)
Removes the paths between index0 and index1 from the selection.

 o clearSelection
 public void clearSelection()
Clears the selection.

 o isSelectionEmpty
 public boolean isSelectionEmpty()
Returns true if the selection is currently empty.

 o addTreeExpansionListener
 public void addTreeExpansionListener(TreeExpansionListener tel)
Adds tel as interested in recieving TreeExpansion events.

 o removeTreeExpansionListener
 public void removeTreeExpansionListener(TreeExpansionListener tel)
Removes tel as being interested in recieving TreeExpansion events.

 o getTreeExpansionListener
 public TreeExpansionListener getTreeExpansionListener()
Returns the multicaster for TreeExpansionEvents.

 o addTreeSelectionListener
 public void addTreeSelectionListener(TreeSelectionListener tsl)
Adds tsl as interested in recieving TreeSelection events.

 o removeTreeSelectionListener
 public void removeTreeSelectionListener(TreeSelectionListener tsl)
Removes tsl as being interested in recieving TreeSelection events.

 o getTreeSelectionListener
 public TreeSelectionListener getTreeSelectionListener()
Returns the multicaster for TreeSelectionEvents.

 o treeDidChange
 public void treeDidChange()
Sent when the tree has changed enough that we need to resize the bounds, but not enough that we need to remove the expanded node set (e.g nodes were expanded or collapsed, or nodes were inserted into the tree)

 o isOpaque
 public boolean isOpaque()
Overrides:
isOpaque in class JComponent

All Packages  Class Hierarchy  This Package  Previous  Next  Index