方法就是调用JFileChooser对象的setFileSelectionMode方法,传入参数JFileChooser.DIRECTORIES_ONLY,使其只选择目录.
JFileChooser chooser=new JFileChooser();
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
if(chooser.showOpenDialog(this)==JFileChooser.APPROVE_OPTION){
System.out.println(chooser.getSelectedFile());
}
转载于:https://blog.51cto.com/smilethat/1075603