Java JTree Expand getExpandedPaths(JTree tree)

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

Description

get Expanded Paths

License

Open Source License

Declaration

static public Collection<TreePath> getExpandedPaths(JTree tree) 

Method Source Code


//package com.java2s;
import java.util.Collection;
import java.util.Comparator;
import java.util.Enumeration;

import java.util.TreeSet;
import javax.swing.JTree;

import javax.swing.tree.TreePath;

public class Main {
    public static Comparator<TreePath> tpLengthComparator = new Comparator<TreePath>() {
        public int compare(TreePath tp1, TreePath tp2) {
            Object[] a1 = tp1.getPath();
            Object[] a2 = tp2.getPath();

            int n1 = a1 != null ? a1.length : 0;
            int n2 = a2 != null ? a2.length : 0;

            return n1 - n2;
        }//from  w  w w  . j  a v  a  2  s .co  m
    };

    static public Collection<TreePath> getExpandedPaths(JTree tree) {
        Collection<TreePath> set = new TreeSet<TreePath>(tpLengthComparator);
        TreePath root = new TreePath(tree.getModel().getRoot());
        if (root != null) {
            for (Enumeration<TreePath> e = tree.getExpandedDescendants(root); e != null && e.hasMoreElements();) {
                TreePath tp = e.nextElement();
                set.add(tp);
            }
        }
        return set;
    }
}

Related

  1. expandTree(JTree tree, boolean expand)
  2. expandTree(JTree tree, TreeNode start, int level)
  3. expandTreeLevels(JTree tree, TreePath parent, boolean expand, int desiredLevel)
  4. expandTreePaths(JTree tree, Enumeration expandPaths)
  5. fullExpand(JTree tree, TreePath parentPath, int nExpansions)
  6. getExpandedPaths(JTree tree)
  7. getLastExpandedNodes(final JTree tree)
  8. getPaths(JTree tree, boolean expanded)
  9. getTreeSelectedExpandedIcon()