Java Utililty Methods JTree Collapse

List of utility methods to do JTree Collapse

Description

The list of methods to do JTree Collapse are organized into topic(s).

Method

voidcollapseAll(JTree tree)
collapse All
expandAll(tree, false);
voidcollapseAllNodes(JTree tree)
collapse All Nodes
int row = tree.getRowCount() - 1;
while (row >= 0) {
    tree.collapseRow(row);
    row--;
tree.expandRow(0);
row = tree.getRowCount() - 1;
while (row >= 0) {
...
voidcollapseAllRows(JTree tree)
collapse All Rows
for (int i = tree.getRowCount() - 1; i >= 0; i--) {
    tree.collapseRow(i);
voidcollapseTree(JTree tree)
Collapses all nodes in a tree.
for (int i = tree.getRowCount() - 1; i > 0; i--) {
    tree.collapseRow(i);
tree.setSelectionRow(0);
voidcollapseTree(JTree tree)
Collapse the tree
final DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
final DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();
collapseSubTree(tree, root, model);
voidfullSelectionCollapse(JTree tree)
full Selection Collapse
int startRow = tree.getLeadSelectionRow();
int stopRow = getStopRow(tree, startRow);
for (int i = stopRow - 1; i >= startRow; --i) {
    tree.collapseRow(i);
IcongetTreeSelectedCollapsedIcon()
get Tree Selected Collapsed Icon
return getTreeCollapsedIcon();
voidsetCollapsedIcon(JTree tree, Icon icon)
Set's the collapsed icon to use for the given JTree if that tree's UI delegate exetends from BasicTreeUI .
if (tree.getUI() instanceof BasicTreeUI) {
    ((BasicTreeUI) tree.getUI()).setCollapsedIcon(icon);