Java JTree Path getDepth(JTree tree)

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

Description

get Depth

License

BSD License

Declaration

static int getDepth(JTree tree) 

Method Source Code

//package com.java2s;
/*   TouchStone design platform is a software to design protocols for lab        *
 *   experiments. It is published under the terms of a BSD license               *
 *   (see details below)                                                         *
 *   Author: Caroline Appert (appert@lri.fr)                                     *
 *   Copyright (c) 2010 Caroline Appert and INRIA, France.                       *
 *   TouchStone design platform reuses parts of an early version which were      *
 *   programmed by Matthis Gilbert.                                              *
 *********************************************************************************/

import javax.swing.JTree;

import javax.swing.tree.TreeNode;

public class Main {
    static int getDepth(JTree tree) {
        TreeNode root = (TreeNode) tree.getModel().getRoot();
        if (root.getChildCount() == 0)
            return 0;
        else/*from w  ww .j a  v a2 s  . c o  m*/
            return 1 + getDepth(root.getChildAt(0));
    }

    static int getDepth(TreeNode tree) {
        if (tree.getChildCount() == 0)
            return 0;
        else
            return 1 + getDepth(tree.getChildAt(0));
    }
}

Related

  1. doNode(JTree tree, TreeNode parentNode, TreePath parentPath)
  2. find2(JTree tree, TreePath parent, Object[] nodes, int depth, boolean byName)
  3. findOrAddNode(JTree tree, TreePath parent, String packageName)
  4. findTreePath(TreePath path, TreeNode node, String pathName)
  5. findV2MetaTreeNode( String nodeXmlPath)
  6. getExpatnedTreePaths(JTree tree)
  7. getObjectPathForNode(final TreeNode node)
  8. getPath(TreeNode node)
  9. getPath(TreeNode treeNode)