import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.control.MenuItem;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
import javafx.stage.Window;

public class MenuMac extends Application {

    @Override
    public void start(Stage stage) {
        final Menu menu = new Menu("Menu");
        final MenuItem topLevelMenuItem = new MenuItem("Top Level Menu Item");

        final Menu subMenu = new Menu("Sub-menu");
        final MenuItem subLevelMenuItem = new MenuItem("Sub Level Menu Item");
        subMenu.getItems().add(subLevelMenuItem);

        menu.getItems().addAll(subMenu, topLevelMenuItem);

        final MenuBar menuBar = new MenuBar();
        menuBar.setUseSystemMenuBar(true);
        menuBar.getMenus().add(menu);

        BorderPane root = new BorderPane();
        root.setTop(menuBar);

        final Button alertButton = new Button("Click Me");
        root.setCenter(alertButton);
        alertButton.setOnAction(e -> createAlert(root.getScene().getWindow(), menuBar));

        Scene scene = new Scene(root, 500, 200);
        stage.setScene(scene);

        stage.show();
    }

    private void createAlert(final Window parentWindow, final MenuBar menuBar) {
        final Alert alert = new Alert(Alert.AlertType.INFORMATION);
        alert.initOwner(parentWindow);
        alert.showingProperty().addListener((obs, ov, isShowing) ->
                menuBar.getMenus().forEach(m -> m.setDisable(isShowing)));
        alert.showAndWait();
    }

}
