When entering fullscreen mode on MacOS, dialogs/alerts are not shown correctly.
Instead a separate tab is opened where the content of the dialog is shown.
The following example program shows the problem:
package prv.rli.codetest;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.ButtonBar.ButtonData;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.control.MenuItem;
import javafx.scene.input.KeyCombination;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class DialogConfirmDangerousAction extends Application {
public DialogConfirmDangerousAction() {
}
@Override
public void start(Stage stage) throws Exception {
stage.setTitle("Dialog default button");
Scene scene = new Scene(new VBox(), 400, 350);
MenuBar menuBar = new MenuBar();
// --- Menu File
Menu menuFile = new Menu("File");
menuBar.getMenus().addAll(menuFile);
MenuItem test = new MenuItem("Open Dialog");
test.setAccelerator(KeyCombination.keyCombination("Ctrl+O"));
test.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent t) {
Alert alert = new Alert(AlertType.CONFIRMATION);
alert.setTitle("Really");
alert.setHeaderText("Danger, Will Robinson");
alert.setContentText("This will make the universe collapse. Are you sure?");
ButtonType yes = new ButtonType("Yes", ButtonData.OTHER);
ButtonType no = new ButtonType("No", ButtonData.CANCEL_CLOSE);
alert.getButtonTypes().setAll(no, yes);
alert.showAndWait();
}
});
menuFile.getItems().add(test);
((VBox) scene.getRoot()).getChildren().addAll(menuBar);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
If it is started, fullscreen mode is entered and the menu item activated, the dialog is shown as described above.