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
-
cellEditor
- Editor for the entries.
-
cellRenderer
- The cell used to draw nodes.
-
editable
- Is the tree editable?
-
expansionListener
- Multicaster for expansion events.
-
rootVisible
- True if the root node is displayed, false if its children are
the highest visible nodes.
-
rowHeight
- Height to use for each row.
-
selectionListener
- Multicaster for tree selection events.
-
selectionModel
- Models the set of selected nodes in this tree.
-
selectionRedirector
- Creates a new event and passed it off the selectionListeners.
-
showsRootHandles
- true if there should be handles at the top level.
-
treeModel
- The model that defines the tree displayed by this object.
-
JTree()
- Returns a JTree with no data model.
-
JTree(TreeModel)
- Returns an instance of JTree using the TreeModel newModel.
-
JTree(TreeNode)
- Returns a JTree with an instance of JTreeModel as its data model,
rooted at root and asksAllowsChildren false.
-
JTree(TreeNode, boolean)
- Returns a JTree with an instance of JTreeModel as its data model.
-
addSelectionInterval(int, int)
- Adds the paths between index0 and index1 to the selection.
-
addSelectionPath(JTreePath)
- Adds the path identified by path to the current selection.
-
addSelectionPaths(JTreePath[])
- Adds each path in paths to the current selection.
-
addSelectionRow(int)
- Adds the path at row to the current selection.
-
addSelectionRows(int[])
- Adds the paths at each of the rows in rows to the current selection.
-
addTreeExpansionListener(TreeExpansionListener)
- Adds tel as interested in recieving TreeExpansion
events.
-
addTreeSelectionListener(TreeSelectionListener)
- Adds tsl as interested in recieving TreeSelection
events.
-
clearSelection()
- Clears the selection.
-
collapsePath(JTreePath)
- Insures that the last item identified in path is collapsed and
visible.
-
collapseRow(int)
- Insures that the item identified by row is collapsed.
-
expandPath(JTreePath)
- Insures that the last item identified in path is expanded and
visible.
-
expandRow(int)
- Insures that the item identified by row is expanded.
-
getCellEditor()
- Returns the editor used to edit entries in the tree.
-
getCellRenderer()
- Returns the current TreeCellRenderer that is rendering each
cell.
-
getClosestPathForLocation(int, int)
- Returns the path to the node that is closest to x,y.
-
getClosestRowForLocation(int, int)
- Returns the row to the node that is closest to x,y.
-
getEditingPath()
- Returns the path to the element that is being edited.
-
getMaxSelectionRow()
- Gets the last selected row.
-
getMinSelectionRow()
- Gets the first selected row.
-
getModel()
- Returns the TreeModel that is providing the data.
-
getPathBetweenRows(int, int)
- Returns JTreePath instances representing the path between index0
and index1 (including index1).
-
getPathBounds(JTreePath)
- Returns the Rectangle that the last item in path will be drawn
into.
-
getPathForRow(int)
- Returns the path for passed in row.
-
getRowBounds(int)
- Returns the Rectangle that the item identified by row will be
drawn into.
-
getRowCount()
- Returns the number of rows that are currently being displayed.
-
getRowForPath(JTreePath)
- Returns the row that the last item identified in path is visible
at.
-
getRowHeight()
- Returns the height of each row.
-
getSelectionModel()
- Returns the model for selections.
-
getSelectionPath()
- Returns the path to the first selected value, or null if
nothing is currently selected.
-
getSelectionPaths()
- Returns the path of the selected values, or null if nothing is
current selected.
-
getSelectionRows()
- Returns all of the currently selected rows.
-
getShowsRootHandles()
- Returns true if handles for the root nodes are displayed.
-
getTreeExpansionListener()
- Returns the multicaster for TreeExpansionEvents.
-
getTreeSelectionListener()
- Returns the multicaster for TreeSelectionEvents.
-
getUI()
- Returns the TreeUI that is providing the current look and
feel.
-
isCollapsed(int)
- Returns true if the value identified by row is currently collapsed.
-
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.
-
isEditable()
- Returns true if the tree is editable.
-
isEditing()
- Returns true if the tree is being edited.
-
isExpanded(int)
- Returns true if the value identified by row is currently expanded.
-
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.
-
isFixedRowHeight()
- Returns true if the height of each row is a fixed size.
-
isOpaque()
-
-
isPathSelected(JTreePath)
- Returns true if item identified by path is currently selected.
-
isRootVisible()
- Returns true if the root node from the TreeModel is currently
visible.
-
isRowSelected(int)
- Returns true if the row identitifed by row is selected.
-
isSelectionEmpty()
- Returns true if the selection is currently empty.
-
isVisible(JTreePath)
- Returns true if the value identified by path is currently visible,
false otherwise.
-
makeVisible(JTreePath)
- Insures that the value identified by path is currently visible.
-
removeSelectionInterval(int, int)
- Removes the paths between index0 and index1 from the selection.
-
removeTreeExpansionListener(TreeExpansionListener)
- Removes tel as being interested in recieving TreeExpansion
events.
-
removeTreeSelectionListener(TreeSelectionListener)
- Removes tsl as being interested in recieving TreeSelection
events.
-
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.
-
scrollRowToVisible(int)
- Scrolls the item identified by row to be visible.
-
setCellEditor(TreeCellEditor)
- Sets the cell editor to cellEditor.
-
setCellRenderer(TreeCellRenderer)
- Sets the TreeCellRenderer that will be used to draw each cell.
-
setEditable(boolean)
- Sets the tree to being editable based on flag.
-
setModel(TreeModel)
- Sets the TreeModel that will provide the data.
-
setRootVisible(boolean)
- Sets, based on rootVisible, whether or not the root node from
the TreeModel is visible.
-
setRowHeight(int)
- Sets the height of each to be rowHeight.
-
setSelectionInterval(int, int)
- Sets the selection to the paths of the nodes between index0 and
index1.
-
setSelectionPath(JTreePath)
-
Sets to selection to the value identified by path.
-
setSelectionPaths(JTreePath[])
-
Sets the selection to paths.
-
setSelectionRow(int)
- The current selection is set to the path for the item at row.
-
setSelectionRows(int[])
- The selection is set to the paths for the items at each of the rows
in rows.
-
setShowsRootHandles(boolean)
- Sets whether or not the root handles are to be displayed.
-
setUI(TreeUI)
- Sets the TreeUI that will provide the current look and feel.
-
startEditingAtPath(JTreePath)
- Selects the last item in path and tries to edit it.
-
stopEditing()
- Stops the current editing session.
-
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)
-
updateUI()
- Called to replace the UI with the latest version from the
default UIFactory.
treeModel
protected TreeModel treeModel
- The model that defines the tree displayed by this object.
selectionModel
protected JTreeSelectionModel selectionModel
- Models the set of selected nodes in this tree.
rootVisible
protected boolean rootVisible
- True if the root node is displayed, false if its children are
the highest visible nodes.
cellRenderer
protected TreeCellRenderer cellRenderer
- The cell used to draw nodes. If null, the UI uses a default
cellRenderer.
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.
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.
expansionListener
protected TreeExpansionListener expansionListener
- Multicaster for expansion events.
selectionListener
protected TreeSelectionListener selectionListener
- Multicaster for tree selection events.
selectionRedirector
protected JTree. TreeSelectionRedirector selectionRedirector
- Creates a new event and passed it off the selectionListeners.
cellEditor
protected TreeCellEditor cellEditor
- Editor for the entries.
editable
protected boolean editable
- Is the tree editable?
JTree
public JTree()
- Returns a JTree with no data model.
JTree
public JTree(TreeNode root)
- Returns a JTree with an instance of JTreeModel as its data model,
rooted at root and asksAllowsChildren false.
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.
JTree
public JTree(TreeModel newModel)
- Returns an instance of JTree using the TreeModel newModel.
getUI
public TreeUI getUI()
- Returns the TreeUI that is providing the current look and
feel.
setUI
public void setUI(TreeUI ui)
- Sets the TreeUI that will provide the current look and feel.
updateUI
public void updateUI()
- Called to replace the UI with the latest version from the
default UIFactory.
- Overrides:
- updateUI in class JComponent
getCellRenderer
public TreeCellRenderer getCellRenderer()
- Returns the current TreeCellRenderer that is rendering each
cell.
setCellRenderer
public void setCellRenderer(TreeCellRenderer x)
- Sets the TreeCellRenderer that will be used to draw each cell.
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.
isEditable
public boolean isEditable()
- Returns true if the tree is editable.
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.
getCellEditor
public TreeCellEditor getCellEditor()
- Returns the editor used to edit entries in the tree. Null implies
the tree can not be edited.
getModel
public TreeModel getModel()
- Returns the TreeModel that is providing the data.
setModel
public void setModel(TreeModel newModel)
- Sets the TreeModel that will provide the data.
isRootVisible
public boolean isRootVisible()
- Returns true if the root node from the TreeModel is currently
visible.
setRootVisible
public void setRootVisible(boolean rootVisible)
- Sets, based on rootVisible, whether or not the root node from
the TreeModel is visible.
setShowsRootHandles
public void setShowsRootHandles(boolean newValue)
- Sets whether or not the root handles are to be displayed.
getShowsRootHandles
public boolean getShowsRootHandles()
- Returns true if handles for the root nodes are displayed.
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.
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.
isFixedRowHeight
public boolean isFixedRowHeight()
- Returns true if the height of each row is a fixed size.
getRowCount
public int getRowCount()
- Returns the number of rows that are currently being displayed.
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.
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.
setSelectionRow
public void setSelectionRow(int row)
- The current selection is set to the path for the item at row.
setSelectionRows
public void setSelectionRows(int rows[])
- The selection is set to the paths for the items at each of the rows
in rows.
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.
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.
addSelectionRow
public void addSelectionRow(int row)
- Adds the path at row to the current selection.
addSelectionRows
public void addSelectionRows(int rows[])
- Adds the paths at each of the rows in rows to the current selection.
getSelectionPath
public JTreePath getSelectionPath()
- Returns the path to the first selected value, or null if
nothing is currently selected.
getSelectionPaths
public JTreePath[] getSelectionPaths()
- Returns the path of the selected values, or null if nothing is
current selected.
getSelectionRows
public int[] getSelectionRows()
- Returns all of the currently selected rows.
getMinSelectionRow
public int getMinSelectionRow()
- Gets the first selected row.
getMaxSelectionRow
public int getMaxSelectionRow()
- Gets the last selected row.
isPathSelected
public boolean isPathSelected(JTreePath path)
- Returns true if item identified by path is currently selected.
isRowSelected
public boolean isRowSelected(int row)
- Returns true if the row identitifed by row is selected.
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.
isExpanded
public boolean isExpanded(int row)
- Returns true if the value identified by row is currently expanded.
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.
isCollapsed
public boolean isCollapsed(int row)
- Returns true if the value identified by row is currently collapsed.
makeVisible
public void makeVisible(JTreePath path)
- Insures that the value identified by path is currently visible.
isVisible
public boolean isVisible(JTreePath path)
- Returns true if the value identified by path is currently visible,
false otherwise.
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.
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.
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.
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.
getPathForRow
public JTreePath getPathForRow(int row)
- Returns the path for passed in row. If row is not visible
null is returned.
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.
expandPath
public void expandPath(JTreePath path)
- Insures that the last item identified in path is expanded and
visible.
expandRow
public void expandRow(int row)
- Insures that the item identified by row is expanded.
collapsePath
public void collapsePath(JTreePath path)
- Insures that the last item identified in path is collapsed and
visible.
collapseRow
public void collapseRow(int row)
- Insures that the item identified by row is collapsed.
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.
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.
isEditing
public boolean isEditing()
- Returns true if the tree is being edited. The item that is being
edited can be returned by getSelectionPath().
stopEditing
public boolean stopEditing()
- Stops the current editing session. This has no effect if the
tree isn't being edited.
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.
getEditingPath
public JTreePath getEditingPath()
- Returns the path to the element that is being edited.
getSelectionModel
public TreeSelectionModel getSelectionModel()
- Returns the model for selections.
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.
setSelectionInterval
public void setSelectionInterval(int index0,
int index1)
- Sets the selection to the paths of the nodes between index0 and
index1.
addSelectionInterval
public void addSelectionInterval(int index0,
int index1)
- Adds the paths between index0 and index1 to the selection.
removeSelectionInterval
public void removeSelectionInterval(int index0,
int index1)
- Removes the paths between index0 and index1 from the selection.
clearSelection
public void clearSelection()
- Clears the selection.
isSelectionEmpty
public boolean isSelectionEmpty()
- Returns true if the selection is currently empty.
addTreeExpansionListener
public void addTreeExpansionListener(TreeExpansionListener tel)
- Adds tel as interested in recieving TreeExpansion
events.
removeTreeExpansionListener
public void removeTreeExpansionListener(TreeExpansionListener tel)
- Removes tel as being interested in recieving TreeExpansion
events.
getTreeExpansionListener
public TreeExpansionListener getTreeExpansionListener()
- Returns the multicaster for TreeExpansionEvents.
addTreeSelectionListener
public void addTreeSelectionListener(TreeSelectionListener tsl)
- Adds tsl as interested in recieving TreeSelection
events.
removeTreeSelectionListener
public void removeTreeSelectionListener(TreeSelectionListener tsl)
- Removes tsl as being interested in recieving TreeSelection
events.
getTreeSelectionListener
public TreeSelectionListener getTreeSelectionListener()
- Returns the multicaster for TreeSelectionEvents.
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)
isOpaque
public boolean isOpaque()
- Overrides:
- isOpaque in class JComponent
All Packages Class Hierarchy This Package Previous Next Index