Rectangle (JTree tree, DefaultMutableTreeNode node, TreePath path) { Rectangle rect = tree.getRowBounds(tree.getRowForPath(path)); if (tree.isExpanded(path)) { Enumeration<TreeNode> children = node.children(); while (children.hasMoreElements()) { DefaultMutableTreeNode child = (DefaultMutableTreeNode)children.nextElement(); TreePath childPath = path.pathByAddingChild(child); assert !path.equals(childPath) : path+";"+child; rect = union(rect, getExpandedNodesRect(tree, child, childPath)); } } return rect; }