Jok*_* 00 4 java javafx path filechooser
我正在使用 JavaFX。我想FileChooser从程序的目录开始,因此初始存储库应该是程序的存储库。
这是我的FileChooser声明:
FileChooser chooser = new FileChooser();
chooser.getExtensionFilters().addAll(
new ExtensionFilter("Text Files", "*.txt"),
new ExtensionFilter("All Files", "*.*"));
chooser.setTitle("Choisir un fichier");
file = chooser.showOpenDialog(new Stage());
我怎样才能做到这一点?
当前目录是“.”。您可以这样做:
FileChooser chooser = new FileChooser();
String currentPath = Paths.get(".").toAbsolutePath().normalize().toString();
chooser.setInitialDirectory(new File(currentPath));
chooser.showOpenDialog(new Stage());
编辑:您应该传递给 FileChooser 的 Stage 或 javafx 节点是您想要成为其父节点的节点。