/** * // Check whether all children are leaf nodes, if so then we expand this // * path, if not then recurse into all children. boolean allLeaves = true; * for (Enumeration en = node.children(); en.hasMoreElements() && allLeaves; ) { * TreeNode child = (TreeNode)en.nextElement(); if (child.isLeaf() == false) { * allLeaves = false; } } if (allLeaves) { tree.expandPath(parent); } else { * for (Enumeration en = node.children(); en.hasMoreElements(); ) { TreeNode * child = (TreeNode)en.nextElement(); if (child.isLeaf() == false) { * expandAll(tree, parent.pathByAddingChild(child)); } } } } */ public void jumpToAndHighlight() { // Set the colouring rule setPattern(pattern); // Collapse everything together before exploding the matching nodes setExpansion(false); DefaultTreeModel treeModel = (DefaultTreeModel) getModel(); DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) treeModel .getRoot(); Enumeration en = rootNode.depthFirstEnumeration(); while (en.hasMoreElements()) { DefaultMutableTreeNode theNode = (DefaultMutableTreeNode) en .nextElement(); if (theNode.getUserObject().toString().toLowerCase().matches( ".*" + pattern + ".*")) { TreePath path = new TreePath(treeModel.getPathToRoot(theNode)); makeVisible(path); } } }