Sometimes you need to find a node in a tree by starting at the root and visiting all children until you have found a match. The
DefaultMutableTreeNode class has several convenience methods for iterating through nodes.
depthFirstEnumeration methods return enumeration objects whose
nextElement method visits all children of the current node, using either a breadth-first or depth-first traversal. Figure 6.31 shows the traversals for a sample tree—the node labels indicate the order in which the nodes are traversed.
Breadth-first enumeration is the easiest to ...