Swings JFileChooser

I have requirement to select sometimes files and sometimes folders using JFileChooser.
For this I set setSelectionMode(JFileChooser.FILES_AND_DIRECTORIES),but I am able to select only files, not able to select directories, any help appreciated?