JFileChooser select just directories

3.5k views Asked by At

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

There are 1 answers

2
loganhuskins On BEST ANSWER

I had AcceptAllFileFilterUsed set to false, which was causing this issue.