我正在使用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());
我该怎么做?
答案 0 :(得分:2)
目前的目录是“。”。以下是如何做到这一点:
FileChooser chooser = new FileChooser();
String currentPath = Paths.get(".").toAbsolutePath().normalize().toString();
chooser.setInitialDirectory(new File(currentPath));
chooser.showOpenDialog(new Stage());
编辑:您应该传递给FileChooser的舞台或javafx节点是您想要成为其父节点的节点。