Java JTree Collapse fullSelectionCollapse(JTree tree)

Here you can find the source of fullSelectionCollapse(JTree tree)

Description

full Selection Collapse

License

Open Source License

Declaration

public static void fullSelectionCollapse(JTree tree) 

Method Source Code

//package com.java2s;

import javax.swing.JTree;

public class Main {
    public static void fullSelectionCollapse(JTree tree) {
        int startRow = tree.getLeadSelectionRow();
        int stopRow = getStopRow(tree, startRow);
        for (int i = stopRow - 1; i >= startRow; --i) {
            tree.collapseRow(i);/*from w w w.j  av a2  s  .  c om*/
        }
    }

    private static int getStopRow(JTree tree, int startRow) {
        int startDepth = tree.getPathForRow(startRow).getPathCount();
        int last = tree.getRowCount();
        int stopRow = last;
        for (int i = startRow + 1; i < last; ++i) {
            int depth = tree.getPathForRow(i).getPathCount();
            if (depth <= startDepth) {
                stopRow = i;
                break;
            }
        }
        return stopRow;
    }
}

Related

  1. collapseAll(JTree tree)
  2. collapseAllNodes(JTree tree)
  3. collapseAllRows(JTree tree)
  4. collapseTree(JTree tree)
  5. collapseTree(JTree tree)
  6. getTreeSelectedCollapsedIcon()
  7. setCollapsedIcon(JTree tree, Icon icon)