setFileSelectionModemode - the type of files to be displayed: 
JFileChooser.FILES_ONLY 
JFileChooser.DIRECTORIES_ONLY 
JFileChooser.FILES_AND_DIRECTORIES
多看看API

解决方案 »

  1.   

    JFileChooser chooser = new JFileChooser();
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
      

  2.   

    import java.io.*;
    import javax.swing.*;public class TestFileChooser {
    public static void main(String[] args){
    JFileChooser jfc=new JFileChooser();
    jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    int i=jfc.showDialog(null,"选择");
    if(0==i){
    File file=jfc.getSelectedFile();
    System.out.println(file);
    System.out.println(file.isDirectory());
    System.out.println (file.getPath());
    }
    }
    }