Browse for folder dialog

Sri Sri picture Sri Sri · Jan 24, 2011 · Viewed 80.6k times · Source

I need to know how to get the "browse for folder" dialog in java. I am aware of SWT. But I need to do in swing? Is there any solution to this?

[As we start on eclipse it will ask for choose workspace. We can see the browse for folder dialog at that time] Thanks in advance.

Answer

Stathis Alexopoulos picture Stathis Alexopoulos · Jan 24, 2011

You can force JFileChooser to select only folders, if you add the following command.

        _fileChooser.setFileSelectionMode( JFileChooser.DIRECTORIES_ONLY);

in the snippet that Bibhaw posted.