Reputation: 225
I want the user to choose where should a certain file be produced in which folder using aJFileChooser
. However, I do not want the user to choose a file, but a folder only.
How would i go on about doing that?
Upvotes: 1
Views: 682
Reputation: 2575
You can do that as follows:
fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
Upvotes: 1
Reputation: 691735
You would use setFileSelectionMode():
Sets the JFileChooser to allow the user to just select files, just select directories, or select both files and directories. The default is JFilesChooser.FILES_ONLY.
Upvotes: 3
Reputation: 262
This should work
JFileChooser chooser = new JFileChooser();
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
Upvotes: 2
Reputation: 347204
Take a look at JFileChooser#setFileSelectionMode(int mode)
Sets the JFileChooser to allow the user to just select files, just select directories, or select both files and directories. The default is JFilesChooser.FILES_ONLY.
Parameters:
mode - the type of files to be displayed:
- JFileChooser.FILES_ONLY
- JFileChooser.DIRECTORIES_ONLY
- JFileChooser.FILES_AND_DIRECTORIES
Upvotes: 2