JavaFX allows selecting a file via FileChooser and selecting a directory via DirectoryChooser, but how do I allow it to select both at once?
Something like Swing's JFileChooser.FILES_AND_DIRECTORIES option.
Currently I'm just using JFileChooser directly, but it's not exactly a good visual match:
JFileChooser chooser = new JFileChooser(".");
chooser.setMultiSelectionEnabled(true);
chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
int ret = chooser.showOpenDialog(null);
if(ret == JFileChooser.APPROVE_OPTION) {
File[] files = chooser.getSelectedFiles();
...
}
JavaFX allows selecting a file via FileChooser and selecting a directory via DirectoryChooser, but how do I allow it to select both at once?
There is no such functionality in JavaFX 2.2 or current JavaFX 8 builds.
A FILES_AND_DIRECTORIES chooser for JavaFX was requested in RT-22621.
The request was declined as Won't Fix for the following reason:
Lubomir Nerad added a comment - Jun, 19 2012 06:59 AM JavaFX uses the corresponding native dialogs for its file and directory chooser. Unless the native file dialogs on all supported platforms can provide this feature, we won't be able to add it to the API.
Lubomir Nerad added a comment - Jul, 24 2012 06:54 AM The requested functionality is not provided by the platform dialogs on Window XP and Linux/GTK.
For Java 8, Windows XP is no longer supported and perhaps Linux will be enhanced to natively provide such functionality so that JavaFX could use it and such a feature could be provided in JavaFX in the future. You may comment on the linked Jira case to register your interest.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With