code: private static void expandAllRecursively(JTree tree, TreePath treePath)
      {
          TreeModel model = tree.getModel();
          Object lastPathComponent = treePath.getLastPathComponent();
          int childCount = model.getChildCount(lastPathComponent);
          if (childCount == 0)
          {
              return;
          }
          tree.expandPath(treePath);
          for (int i=0; i<childCount; i++)
          {
              Object child = model.getChild(lastPathComponent, i);
              int grandChildCount = model.getChildCount(child);
              if (grandChildCount > 0)
              {
                  class LocalTreePath extends TreePath
                  {
                      private static final long serialVersionUID = 0;
                      public LocalTreePath(
                          TreePath parent, Object lastPathComponent)
                      {
                          super(parent, lastPathComponent);
                      }
                  }
                  TreePath nextTreePath = new LocalTreePath(treePath, child);
                  expandAllRecursively(tree, nextTreePath);
              }
          }
      }
docs: Recursively expand all paths in the given tree, starting with the
  given path
  
  @param tree The tree
  @param treePath The current tree path