Java JTree Path findOrAddNode(JTree tree, TreePath parent, String packageName)

Here you can find the source of findOrAddNode(JTree tree, TreePath parent, String packageName)

Description

find Or Add Node

License

Apache License

Declaration

public static DefaultMutableTreeNode findOrAddNode(JTree tree, TreePath parent, String packageName) 

Method Source Code


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

import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;

import javax.swing.tree.TreePath;
import java.util.Enumeration;

public class Main {

    public static DefaultMutableTreeNode findOrAddNode(JTree tree, TreePath parent, String packageName) {
        final DefaultMutableTreeNode node = (DefaultMutableTreeNode) parent.getLastPathComponent();

        for (final Enumeration e = node.children(); e.hasMoreElements();) {
            final DefaultMutableTreeNode n = (DefaultMutableTreeNode) e.nextElement();
            if (packageName.equals(n.toString()))
                return n;
        }// w  ww. j  a  v  a 2s . c  o m

        final DefaultMutableTreeNode nodeCls = new DefaultMutableTreeNode(packageName);
        node.add(nodeCls);
        return nodeCls;
    }
}

Related

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