Here you can find the source of findOrAddNode(JTree tree, TreePath parent, String packageName)
public static DefaultMutableTreeNode findOrAddNode(JTree tree, TreePath parent, String packageName)
//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; } }