public class JTrees extends Object
| Modifier and Type | Method and Description |
|---|---|
static void |
applyButtonTreeCellRenderer(JTree tree,
Function<Object,JButton> buttonFactory,
Function<Object,String> textFactory)
Apply a cell renderer to the given tree that will create cells that
consist of a button and a label, based on
a
GenericTreeCellRenderer. |
static void |
collapseAll(JTree tree,
boolean omitRoot)
Collapse all rows of the given tree
|
static List<TreePath> |
computeExpandedPaths(JTree tree)
Compute the list of all tree paths in the given tree that are currently
expanded
|
static int |
computeIndexInParent(Object nodeObject)
Computes the index that the given node has in its parent node.
|
static int |
countNodes(TreeModel treeModel)
Count the number of nodes in the given tree model
|
static TreePath |
createTreePathToRoot(TreeModel treeModel,
Object node)
Returns the tree path from the given node to the root in the
given tree model
|
static void |
expandAll(JTree tree)
Expand all rows of the given tree.
|
static void |
expandAllFixedHeight(JTree tree)
Expand all rows of the given tree, assuming a fixed height for
the rows.
|
static DefaultMutableTreeNode |
findNode(TreeModel treeModel,
Object userObject)
Returns the first node with the given user object in the tree with
the given model.
|
static List<Object> |
getAllDescendants(TreeModel treeModel,
Object node)
Return all descendants of the given node in the given tree model
(not including the given node!)
|
static List<Object> |
getAllNodes(TreeModel treeModel)
Return all nodes of the given tree model
|
static List<Object> |
getChildren(TreeModel treeModel,
Object node)
Returns the children of the given node in the given tree model
|
static List<Object> |
getLeafNodes(TreeModel treeModel)
Returns a list containing all leaf nodes from the given tree model.
|
static List<Object> |
getLeafNodes(TreeModel treeModel,
Object node)
Returns a list containing all leaf nodes from the given tree model
that are descendants of the given node.
|
static Object |
getParent(TreeModel treeModel,
Object node)
Returns the parent of the given node in the given tree model.
|
static Object |
getUserObjectFromTreeNode(Object nodeObject)
Returns the user object from the given tree node.
|
static Object |
getUserObjectFromTreePath(TreePath treePath)
Returns the user object from the last path component of the given tree
path.
|
static TreePath |
translatePath(TreeModel newTreeModel,
TreePath oldPath)
Translates one TreePath to a new TreeModel.
|
static TreePath |
translatePath(TreeModel newTreeModel,
TreePath oldPath,
BiPredicate<Object,Object> equality)
Translates one TreePath to a new TreeModel.
|
public static void expandAll(JTree tree)
expandAllFixedHeight(JTree) may
be significantly faster.tree - The treepublic static void expandAllFixedHeight(JTree tree)
tree - The treepublic static void collapseAll(JTree tree, boolean omitRoot)
tree - The treeomitRoot - Whether the root node should not be collapsedpublic static int countNodes(TreeModel treeModel)
treeModel - The tree modelpublic static DefaultMutableTreeNode findNode(TreeModel treeModel, Object userObject)
null if no matching node is found.treeModel - The tree modeluserObject - The user objectnullpublic static List<Object> getChildren(TreeModel treeModel, Object node)
treeModel - The tree modelnode - The nodepublic static Object getParent(TreeModel treeModel, Object node)
null, if the given node is
the root node (or not contained in the tree model at all).treeModel - The tree modelnode - The nodepublic static List<Object> getAllNodes(TreeModel treeModel)
treeModel - The tree modelpublic static List<Object> getAllDescendants(TreeModel treeModel, Object node)
treeModel - The tree modelnode - The nodepublic static List<Object> getLeafNodes(TreeModel treeModel)
treeModel - The tree modelpublic static List<Object> getLeafNodes(TreeModel treeModel, Object node)
treeModel - The tree modelnode - The node to start the search frompublic static TreePath createTreePathToRoot(TreeModel treeModel, Object node)
treeModel - The tree modelnode - The nodepublic static List<TreePath> computeExpandedPaths(JTree tree)
tree - The treepublic static TreePath translatePath(TreeModel newTreeModel, TreePath oldPath)
newTreeModel - The new tree modeloldPath - The old tree pathnull if there is no
corresponding path in the new tree modelpublic static TreePath translatePath(TreeModel newTreeModel, TreePath oldPath, BiPredicate<Object,Object> equality)
newTreeModel - The new tree modeloldPath - The old tree pathequality - The equality predicatenull if there is no
corresponding path in the new tree modelpublic static Object getUserObjectFromTreePath(TreePath treePath)
null, then null
is returned. If the last path component is not a DefaultMutableTreeNode,
then null is returned.treePath - The tree pathpublic static Object getUserObjectFromTreeNode(Object nodeObject)
null or not a DefaultMutableTreeNode,
then null is returned.nodeObject - The node objectpublic static int computeIndexInParent(Object nodeObject)
nodeObject - The nodepublic static void applyButtonTreeCellRenderer(JTree tree, Function<Object,JButton> buttonFactory, Function<Object,String> textFactory)
GenericTreeCellRenderer.tree - The treebuttonFactory - The factory that will receive the tree node,
and return the JButton (to which listeners may already have been
attached). If this function returns null, then no
button will be inserted.textFactory - The factory that will receive the tree node,
and return the text that should be displayed as the node label.Copyright © 2022. All rights reserved.