code: public static void enableAutoExpansion(final JTree tree) {
  
      tree.getModel().addTreeModelListener(new TreeModelListener() {
  
        public void treeNodesChanged(TreeModelEvent e) {
          // nothing to do
        }
  
        public void treeNodesInserted(TreeModelEvent e) {
          tree.expandPath(e.getTreePath());
        }
  
        public void treeNodesRemoved(TreeModelEvent e) {
          // nothing to do
        }
  
        public void treeStructureChanged(TreeModelEvent e) {
          // nothing to do
        }
  
      });
  
    }
docs: Adds a <code>TreeModelListener</code> that will automatically expand
  the tree as new nodes are inserted.
  @param tree The <code>JTree</code>.