Swing Java Tutorial

The fileSelectionMode property setting determines the mode of the chooser.
The available settings are specified by the three JFileChooser constants:
FILES_ONLY,
DIRECTORIES_ONLY, and
FILES_AND_DIRECTORIES.
Initially, the file chooser is in JFileChooser.FILES_ONLY mode.
To change the mode, just call public void setFileSelectionMode(int newMode).

import javax.swing.JFileChooser;
public class JFileChooserSelectionMode {
  public static void main(String[] a) {
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    fileChooser.showOpenDialog(null);
  }
}