import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.layout.StackPane; import javafx.scene.layout.VBox; import javafx.stage.DirectoryChooser; import javafx.stage.Modality; import javafx.stage.Stage; public class DirChooser extends Application { public static void main(String[] args) { launch(args); } @Override public void start(final Stage primaryStage) { primaryStage.setScene(new Scene(new StackPane(), 300, 250)); primaryStage.show(); showMessageBox(primaryStage); } private void showMessageBox(final Stage primaryStage) { final Stage msgBox = new Stage(); msgBox.initModality(Modality.APPLICATION_MODAL); msgBox.setResizable(false); Button okButton = new Button("OK"); okButton.setOnAction(new EventHandler() { @Override public void handle(ActionEvent event) { msgBox.close(); DirectoryChooser dirChooser = new DirectoryChooser(); System.out.println("selected file: " + dirChooser.showDialog(primaryStage)); System.out.println( "On Mac you can see this line while the chooser is still active! " + "No Directoy has been selected yet and therefore the selected file is null. " + "The actual selected Directory is lost somewhere in Nirvana..."); } }); VBox contentBox = new VBox(); contentBox.getChildren().add(okButton); msgBox.setScene(new Scene(contentBox, 200, 100)); msgBox.showAndWait(); } }