JFileChooser select just directories

时间:2015-06-15 14:48:57

标签: java swing jfilechooser

I am using JFileChooser to allow the user of my application to select a directory for file storage. Per the documentation and other StackOverflow questions I have researched I have added this bit of code:

fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

Doing this does return the directory that I need, but to select that directory you have to select a file in that directory. If the directory is empty you have to create a file in it to select. My question is, is there a way to display only directories and to be able to select from those directories even if they have sub-directories?

1 个答案:

答案 0 :(得分:0)

我将AcceptAllFileFilterUsed设置为false,这导致了这个问题。