Java JTree Model getTreeModelSize(TreeModel in)

Here you can find the source of getTreeModelSize(TreeModel in)

Description

return the size of a tree model

License

Apache License

Parameter

Parameter Description
in - the tree model

Return

- the size >= 0

Declaration

public static int getTreeModelSize(TreeModel in) 

Method Source Code

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

import javax.swing.tree.*;

public class Main {
    /**/*w  w  w  .  ja v  a2  s.c o  m*/
    return the size of a tree model
    @param in - the tree model
    @return - the size >= 0
    */
    public static int getTreeModelSize(TreeModel in) {
        Object root = in.getRoot();
        if (root == null)
            return (0);
        return (getTreeModelSize(in, root));
    }

    /**
    return the size of a tree starting at a specific root
    @param in - the tree model
    @parem root - starting node - non-null
    @return - the size >= 1
    */
    protected static int getTreeModelSize(TreeModel in, Object root) {
        int ret = 1; // add one for root
        for (int i = 0; i < in.getChildCount(root); i++)
            ret += getTreeModelSize(in, in.getChild(root, i));
        return (ret);
    }
}

Related

  1. findChildNode(TreeModel model, Object node, String text)
  2. findChildNode(TreeModel model, Object node, String text)
  3. findTreeNode(TreeModel model, Object obj)
  4. getAllTreeNodes(TreeModel model)
  5. getTreeIndents(TreeModel in)
  6. isTreePathInModel(TreeModel treeModel, TreePath treePath)
  7. logTreeNodes(TreeModel model, Object node, String indent)
  8. nodesChanged(DefaultTreeModel rightTreeModel)
  9. redrawAllTreeCells(DefaultTreeModel treeModel)