【发布时间】:2018-07-23 08:11:19
【问题描述】:
我想从 JavaFX 中的 FileChooser showSaveDialog() 对话框中获取选定的文件路径,以便将 tableview 导出到文件。 代码在 Runnable 中运行,因此我必须在 JavaFX 主线程 (Platform.runLater) 中运行 showSaveDialog
public class ExportUtils {
...
private File file = null;
private String outputPath = null;
public void Export(){
...
ChooseDirectory(stage);
if (outputPath != null{
... //export to the selected path
}
}
public void ChooseDirectory(Stage stage) {
...
FileChooser newFileChooser = new FileChooser();
...
Platform.runLater(new Runnable() {
public void run() {
file = newFileChooser.showSaveDialog(stage);
if (file != null) {
outputPath = file.getPath();
}
}
});
}
我想知道这种情况的最佳解决方案,在我评估 Export() 方法中的 outputPath 变量的值之前,我必须等待用户选择路径和文件名。
【问题讨论】:
标签: multithreading javafx filechooser