javax.swing
public class JTree extends JComponent implements Scrollable, Accessible
Nested Class Summary | |
---|---|
protected class | JTree.AccessibleJTree
This class implements accessibility support for the JTree class. |
static class | JTree.DynamicUtilTreeNode |
protected static class | JTree.EmptySelectionModel
A TreeModel that does not allow anything to be selected. |
protected class | JTree.TreeModelHandler
Listens to the model of the JTree and updates the property
expandedState if nodes are removed or changed. |
protected class | JTree.TreeSelectionRedirector
This redirects TreeSelectionEvents and rewrites the source of it to be
this JTree. |
Constructor Summary | |
---|---|
JTree()
Creates a new JTree object. | |
JTree(Hashtable<?,?> value)
Creates a new JTree object.
| |
JTree(Object[] value)
Creates a new JTree object.
| |
JTree(TreeModel model)
Creates a new JTree object.
| |
JTree(TreeNode root)
Creates a new JTree object.
| |
JTree(TreeNode root, boolean asksAllowChildren)
Creates a new JTree object.
| |
JTree(Vector<?> value)
Creates a new JTree object.
|
Method Summary | |
---|---|
void | addSelectionInterval(int index0, int index1)
Select all rows between the two given indexes, inclusive. |
void | addSelectionPath(TreePath path) |
void | addSelectionPaths(TreePath[] paths) |
void | addSelectionRow(int row) |
void | addSelectionRows(int[] rows) |
void | addTreeExpansionListener(TreeExpansionListener listener)
Adds a TreeExpansionListener object to the tree.
|
void | addTreeSelectionListener(TreeSelectionListener listener)
Adds a TreeSelctionListener object to the tree.
|
void | addTreeWillExpandListener(TreeWillExpandListener listener)
Adds a TreeWillExpandListener object to the tree.
|
void | cancelEditing() |
void | clearSelection() |
protected void | clearToggledPaths() |
void | collapsePath(TreePath path) |
void | collapseRow(int row) |
String | convertValueToText(Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus)
Converts the specified value to a String. |
protected static TreeModel | createTreeModel(Object value)
Creates a new TreeModel object.
|
protected TreeModelListener | createTreeModelListener()
Creates and returns an instance of {@link TreeModelHandler}.
|
void | expandPath(TreePath path) |
void | expandRow(int row) |
void | fireTreeCollapsed(TreePath path)
Notifies all listeners that the tree was collapsed.
|
void | fireTreeExpanded(TreePath path)
Notifies all listeners that the tree was expanded.
|
void | fireTreeWillCollapse(TreePath path)
Notifies all listeners that the tree will collapse.
|
void | fireTreeWillExpand(TreePath path)
Notifies all listeners that the tree will expand.
|
protected void | fireValueChanged(TreeSelectionEvent event)
Notifies all listeners when the selection of the tree changed.
|
AccessibleContext | getAccessibleContext()
Gets the AccessibleContext associated with this
JTree .
|
TreePath | getAnchorSelectionPath() |
TreeCellEditor | getCellEditor() |
TreeCellRenderer | getCellRenderer() |
TreePath | getClosestPathForLocation(int x, int y) |
int | getClosestRowForLocation(int x, int y) |
protected static TreeModel | getDefaultTreeModel()
Returns a sample TreeModel that can be used in a JTree. |
protected Enumeration<TreePath> | getDescendantToggledPaths(TreePath parent) |
boolean | getDragEnabled()
Return the value of the dragEnabled property.
|
TreePath | getEditingPath() |
Enumeration<TreePath> | getExpandedDescendants(TreePath path)
Returns all TreePath objects which are a descendants of the given path
and are exapanded at the moment of the execution of this method. |
boolean | getExpandsSelectedPaths() |
boolean | getInvokesStopCellEditing() |
Object | getLastSelectedPathComponent() |
TreePath | getLeadSelectionPath() |
int | getLeadSelectionRow() |
int | getMaxSelectionRow() |
int | getMinSelectionRow() |
TreeModel | getModel()
Returns the model of this JTree object.
|
TreePath | getNextMatch(String prefix, int startingRow, Position.Bias bias)
Returns the next table element (beginning from the row
startingRow that starts with prefix .
|
protected TreePath[] | getPathBetweenRows(int index0, int index1)
Get the pathes that are displayes between the two given rows.
|
Rectangle | getPathBounds(TreePath path) |
TreePath | getPathForLocation(int x, int y) |
TreePath | getPathForRow(int row) |
Dimension | getPreferredScrollableViewportSize()
Returns the preferred viewport size.
|
Rectangle | getRowBounds(int row) |
int | getRowCount() |
int | getRowForLocation(int x, int y) |
int | getRowForPath(TreePath path) |
int | getRowHeight() |
int | getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction) |
boolean | getScrollableTracksViewportHeight() |
boolean | getScrollableTracksViewportWidth() |
int | getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction)
Return the preferred scrolling amount (in pixels) for the given scrolling
direction and orientation. |
boolean | getScrollsOnExpand() |
int | getSelectionCount() |
TreeSelectionModel | getSelectionModel() |
TreePath | getSelectionPath() |
TreePath[] | getSelectionPaths() |
int[] | getSelectionRows() |
boolean | getShowsRootHandles() |
int | getToggleClickCount() |
TreeExpansionListener[] | getTreeExpansionListeners()
Returns all added TreeExpansionListener objects.
|
TreeSelectionListener[] | getTreeSelectionListeners()
Returns all added TreeSelectionListener objects.
|
TreeWillExpandListener[] | getTreeWillExpandListeners()
Returns all added TreeWillExpandListener objects.
|
TreeUI | getUI()
Return the UI associated with this JTree object.
|
String | getUIClassID()
This method returns the String ID of the UI class of Separator.
|
int | getVisibleRowCount() |
boolean | hasBeenExpanded(TreePath path) |
boolean | isCollapsed(TreePath path) |
boolean | isCollapsed(int row) |
boolean | isEditable()
Checks if this JTree object is editable.
|
boolean | isEditing() |
boolean | isExpanded(TreePath path) |
boolean | isExpanded(int row) |
boolean | isFixedRowHeight() |
boolean | isLargeModel() |
boolean | isPathEditable(TreePath path) |
boolean | isPathSelected(TreePath path) |
boolean | isRootVisible()
Checks if the root element is visible.
|
boolean | isRowSelected(int row)
Returns true when the specified row is selected,
false otherwise. |
boolean | isSelectionEmpty() |
boolean | isVisible(TreePath path) |
void | makeVisible(TreePath path) |
protected String | paramString()
A String representation of this JTree. |
protected boolean | removeDescendantSelectedPaths(TreePath path, boolean includeSelected)
Removes any paths in the current set of selected paths that are
descendants of path . |
protected void | removeDescendantToggledPaths(Enumeration<TreePath> toRemove)
Removes any descendants of the TreePaths in toRemove that have been
expanded.
|
void | removeSelectionInterval(int index0, int index1) |
void | removeSelectionPath(TreePath path) |
void | removeSelectionPaths(TreePath[] paths) |
void | removeSelectionRow(int row) |
void | removeSelectionRows(int[] rows) |
void | removeTreeExpansionListener(TreeExpansionListener listener)
Removes a TreeExpansionListener object from the tree.
|
void | removeTreeSelectionListener(TreeSelectionListener listener)
Removes a TreeSelectionListener object from the tree.
|
void | removeTreeWillExpandListener(TreeWillExpandListener listener)
Removes a TreeWillExpandListener object from the tree.
|
void | scrollPathToVisible(TreePath path) |
void | scrollRowToVisible(int row) |
void | setAnchorSelectionPath(TreePath path) |
void | setCellEditor(TreeCellEditor editor) |
void | setCellRenderer(TreeCellRenderer newRenderer) |
void | setDragEnabled(boolean enabled)
Set the dragEnabled property.
|
void | setEditable(boolean flag)
Sets the editable property.
|
protected void | setExpandedState(TreePath path, boolean state) |
void | setExpandsSelectedPaths(boolean flag) |
void | setInvokesStopCellEditing(boolean invoke) |
void | setLargeModel(boolean large) |
void | setLeadSelectionPath(TreePath path) |
void | setModel(TreeModel model)
Sets the model to use in JTree .
|
void | setRootVisible(boolean flag) |
void | setRowHeight(int height) |
void | setScrollsOnExpand(boolean scroll) |
void | setSelectionInterval(int index0, int index1) |
void | setSelectionModel(TreeSelectionModel model) |
void | setSelectionPath(TreePath path) |
void | setSelectionPaths(TreePath[] paths) |
void | setSelectionRow(int row) |
void | setSelectionRows(int[] rows) |
void | setShowsRootHandles(boolean flag) |
void | setToggleClickCount(int count) |
void | setUI(TreeUI ui)
Sets the UI associated with this JTree object.
|
void | setVisibleRowCount(int rows) |
void | startEditingAtPath(TreePath path) |
boolean | stopEditing() |
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). |
void | updateUI()
This method resets the UI used to the Look and Feel defaults.. |
Since: 1.3
Since: 1.3
Since: 1.3
JTree
object.JTree
object.
Parameters: value the initial nodes in the tree
JTree
object.
Parameters: value the initial nodes in the tree
JTree
object.
Parameters: model the model to use
JTree
object.
Parameters: root the root node
JTree
object.
Parameters: root the root node asksAllowChildren if false, all nodes without children are leaf nodes. If true, only nodes that do not allow children are leaf nodes.
JTree
object.
Parameters: value the initial nodes in the tree
Parameters: index0 the starting row, inclusive index1 the ending row, inclusive
TreeExpansionListener
object to the tree.
Parameters: listener the listener to add
TreeSelctionListener
object to the tree.
Parameters: listener the listener to add
TreeWillExpandListener
object to the tree.
Parameters: listener the listener to add
value.toString()
and
ignores all other parameters. Subclass this method to control the
conversion.
Parameters: value the value that is converted to a String selected indicates if that value is selected or not expanded indicates if that value is expanded or not leaf indicates if that value is a leaf node or not row the row of the node hasFocus indicates if that node has focus or not
TreeModel
object.
Parameters: value the values stored in the model
Returns: an instance of {@link TreeModelHandler}
Parameters: path the path to the node that was collapsed
Parameters: path the path to the node that was expanded
Parameters: path the path to the node that will collapse
Parameters: path the path to the node that will expand
Parameters: event the event to send
JTree
.
Returns: the associated context
Since: 1.3
Returns: a sample TreeModel that can be used in a JTree
dragEnabled
property.
Returns: the value
Since: 1.4
Parameters: path The parent of this request
Returns: An Enumeration containing TreePath objects
Since: 1.3
JTree
object.
Returns: the associated TreeModel
startingRow
that starts with prefix
.
Searching is done in the direction specified by bias
.
Parameters: prefix the prefix to search for in the cell values startingRow the index of the row where to start searching from bias the search direction, either {@link Position.Bias#Forward} or {@link Position.Bias#Backward}
Returns: the path to the found element or -1 if no such element has been found
Throws: IllegalArgumentException if prefix is null
or
startingRow is not valid
Since: 1.4
Parameters: index0 the starting row, inclusive index1 the ending row, inclusive
Returns: the array of the tree pathes
Returns: the preferred size
Parameters: visibleRect the currently visible part of the component. orientation the scrolling orientation direction the scrolling direction (negative - up, positive -down). The values greater than one means that more mouse wheel or similar events were generated, and hence it is better to scroll the longer distance.
Since: 1.3
TreeExpansionListener
objects.
Returns: an array of listeners
TreeSelectionListener
objects.
Returns: an array of listeners
TreeWillExpandListener
objects.
Returns: an array of listeners
JTree
object.
Returns: the associated TreeUI
object
Returns: The UI class' String ID.
JTree
object is editable.
Returns: true
if this tree object is editable,
false
otherwise
Returns: true
if the root element is visible,
false
otherwise
true
when the specified row is selected,
false
otherwise. This call is delegated to the
{@link TreeSelectionModel#isRowSelected(int)} method.
Parameters: row the row to check
Returns: true
when the specified row is selected,
false
otherwise
null
.
Returns: a String representation of this JTree
path
. If includePath
is set
to true
and path
itself is selected, then
it will be removed too.
Parameters: path the path from which selected descendants are to be removed includeSelected if true
then path
itself
will also be remove if it's selected
Returns: true
if something has been removed,
false
otherwise
Since: 1.3
Parameters: toRemove - Enumeration of TreePaths that need to be removed from cache of toggled tree paths.
TreeExpansionListener
object from the tree.
Parameters: listener the listener to remove
TreeSelectionListener
object from the tree.
Parameters: listener the listener to remove
TreeWillExpandListener
object from the tree.
Parameters: listener the listener to remove
Since: 1.3
dragEnabled
property.
Parameters: enabled new value
Since: 1.4
editable
property.
Parameters: flag true
to make this tree object editable,
false
otherwise
Since: 1.3
Since: 1.3
JTree
.
Parameters: model the TreeModel
to use
Since: 1.3
JTree
object.
Parameters: ui the TreeUI
to associate
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). You should never have to invoke this, the UI will invoke this as it needs to.
If the tree uses {@link DefaultTreeModel}, you must call {@link DefaultTreeModel#reload(TreeNode)} or {@link DefaultTreeModel#reload()} after adding or removing nodes. Following the official Java 1.5 API standard, just calling treeDidChange, repaint() or revalidate() does not update the tree appearance properly.
See Also: reload