I want to restrict JavaFX File chooser to its initial directory.
I've seen that it's possible in Swing (How do I restrict JFileChooser to a directory?) but I could not find anything similar in java fx.
Is there a way to achieve this?
This probably is a environment based window, and until java Specifies a Class for that (Which I feel it does not), you really can't do anything about it.
But you could always let the user choose the directory and then check the directory and if it does not match your criteria, you could set the value to null and ask the user to input it again
File f = fileChooser.showOpenDialog(primaryStage);
if(f.getAbsolutePath().matches("regex")){
//Do Something
}
Here regex would be replaced with somethinglike this
[.+]//yourPath
If you want to know more about regex, Visit here
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