I want to get the selected file path from a FileChooser showSaveDialog() dialog in JavaFX in order to export a tableview to a file. The code is running in a Runnable so I have to run the showSaveDialog in a JavaFX main thread (Platform.runLater)
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();
}
}
});
}
I would like to know the best solution for this situation where I have to wait for the user to choose the path and filename before I evaluate the value of the outputPath variable in the Export() method.