Java JTree Model findChildNode(TreeModel model, Object node, String text)

Here you can find the source of findChildNode(TreeModel model, Object node, String text)

Description

Returns the node with the given text below the given node in the specified TreeModel

License

Open Source License

Parameter

Parameter Description
model the TreeModel to search
node the node to search below
text the text associated with the required node

Return

the required node, if found; otherwise null

Declaration

static Object findChildNode(TreeModel model, Object node, String text) 

Method Source Code

//package com.java2s;
// it under the terms of the GNU General Public License as published by

import javax.swing.tree.TreeModel;

public class Main {
    /**// w  w  w .j a  v a 2 s .c  om
     * Returns the node with the given text below the given node in the specified TreeModel
     * @param model
     *  the TreeModel to search
     * @param node
     *  the node to search below
     * @param text
     *  the text associated with the required node
     * @return
     * the required node, if found; otherwise null
     */
    static Object findChildNode(TreeModel model, Object node, String text) {
        for (int i = 0; i < model.getChildCount(node); i++) {
            Object currNode = model.getChild(node, i);
            if (currNode.toString() != null && currNode.toString().equals(text))
                return currNode;
        }
        return null;
    }
}

Related

  1. appendTreeNodes(TreeModel model, Object node, StringBuilder builder, String indent)
  2. findChildNode(TreeModel model, Object node, String text)
  3. findTreeNode(TreeModel model, Object obj)
  4. getAllTreeNodes(TreeModel model)
  5. getTreeIndents(TreeModel in)