Java Code Examples for javax.swing.tree.TreeNode#toString()
The following examples show how to use
javax.swing.tree.TreeNode#toString() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RandomArmyDialog.java From megamek with GNU General Public License v2.0 | 5 votes |
private TreePath findNextNode(TreePath parent, String[] nodes, int depth) { TreeNode node = (TreeNode)parent.getLastPathComponent(); String currNode = node.toString(); // If equal, go down the branch if (currNode.equals(nodes[depth].trim())) { // If at end, return match if (depth == nodes.length-1) { return parent; } // Traverse children if (node.getChildCount() >= 0) { for (Enumeration<?> e = node.children(); e.hasMoreElements(); ) { TreeNode n = (TreeNode)e.nextElement(); TreePath path = parent.pathByAddingChild(n); TreePath result = findNextNode(path, nodes, depth + 1); // Found a match if (result != null) { return result; } } } } // No match at this branch return null; }
Example 2
Source File: DebugNode.java From Pixelitor with GNU General Public License v3.0 | 5 votes |
public String toDetailedString() { if (userObject == null) { return name + " = null"; } @SuppressWarnings("unchecked") Enumeration<TreeNode> childrenEnum = children(); StringBuilder sb = new StringBuilder(); indent(sb, getLevel()); sb.append(name).append(" {"); while (childrenEnum.hasMoreElements()) { indent(sb, getLevel() + 1); TreeNode t = childrenEnum.nextElement(); String info; if (t instanceof DebugNode) { DebugNode dn = (DebugNode) t; info = dn.toDetailedString(); } else { info = t.toString(); } sb.append(info); } indent(sb, getLevel()); sb.append('}'); return sb.toString(); }
Example 3
Source File: TreeUtil.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
public static TreePath buildTreePath(JTree tree, TreePath parent, String[] nodes, int startdepth, boolean expandable) { TreeNode node = (TreeNode) parent.getLastPathComponent(); String o = node.toString(); // If equal, go down the branch if (o.equals(nodes[startdepth])) { // If at end, return match if (startdepth == nodes.length - 1) { return parent; } // Traverse children if (node.getChildCount() >= 0) { for (Enumeration e = node.children(); e.hasMoreElements();) { TreeNode n = (TreeNode) e.nextElement(); TreePath path = parent.pathByAddingChild(n); if (n.isLeaf() && expandable) { return parent; } TreePath result = buildTreePath(tree, path, nodes, startdepth + 1,expandable); // Found a match if (result != null) { return result; } } } } // No match at this branch return null; }