Restrict JavaFX filechooser to initial folder
•
Java
I want to limit the JavaFX file selector to its initial directory
Is there any way to achieve this goal?
Solution
This may be an environment - based window. Until Java specifies a class (I don't think it does), you really can't do anything
However, you can always let the user select the directory and check the directory. If it does not conform to your standard, you can set the value to null and ask the user to enter it again
File f = fileChooser.showOpenDialog(primaryStage); if(f.getAbsolutePath().matches("regex")){ //Do Something }
The regular expression here will be replaced with something similar
[.+]//yourPath
If you want to learn more about regular expressions, visit here
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码