Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restrict JavaFX FileChooser to initial folder

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?

like image 762
Tzach Solomon Avatar asked Nov 09 '22 10:11

Tzach Solomon


1 Answers

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

like image 72
dumbPotato21 Avatar answered Dec 10 '22 15:12

dumbPotato21