将程序的目录设置为 JavaFX FileChooser 的初始目录
Set program's directory as the initial directory of JavaFX 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 节点是您希望成为其父级的节点。
我正在使用 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 节点是您希望成为其父级的节点。