Java JTree getExpansionState(JTree tree, int row)

Here you can find the source of getExpansionState(JTree tree, int row)

Description

get Expansion State

License

Open Source License

Declaration

public static String getExpansionState(JTree tree, int row) 

Method Source Code

//package com.java2s;
//License from project: MIT License 

import javax.swing.JTree;
import javax.swing.tree.TreePath;

public class Main {
    public static String getExpansionState(JTree tree, int row) {
        TreePath rowPath = tree.getPathForRow(row);
        StringBuffer buf = new StringBuffer();
        int rowCount = tree.getRowCount();
        for (int i = row; i < rowCount; i++) {
            TreePath path = tree.getPathForRow(i);
            if (i == row || isDescendant(path, rowPath)) {
                if (tree.isExpanded(path))
                    buf.append("," + String.valueOf(i - row));
            } else
                break;
        }/*w  w w.ja  v  a 2  s  . c om*/
        return buf.toString();
    }

    public static boolean isDescendant(TreePath path1, TreePath path2) {
        int count1 = path1.getPathCount();
        int count2 = path2.getPathCount();
        if (count1 <= count2)
            return false;
        while (count1 != count2) {
            path1 = path1.getParentPath();
            count1--;
        }
        return path1.equals(path2);
    }
}

Related

  1. disposeExpressionsTree()
  2. enableAutoExpansion(final JTree tree)
  3. findByName(JTree tree, String[] names)
  4. findTree(Container container)
  5. getCurrentWidth(JTree tree, int row)
  6. getProjectTree()
  7. getSelectionFromTree(JTree tree)
  8. getStopRow(JTree tree, int startRow)
  9. getTreeImage(String imageName)