I'm trying to display an alert on top of another alert in a full-screen JavaFX application. Without full-screen it works fine, the second alert is displayed on top of the first alert. With full-screen however the second alert is displayed under the first one despite having focus as shown in the first screenshot. Is it possible to have the second alert displayed on top?
Also as another issue regarding alerts in full-screen, when going to the desktop or alt+tab in Windows the alert is displayed despite setting the parent stage as owner as shown in the second screenshot (only the first alert for some reason). Is it possible to have the alerts tied to the full-screen parent stage so they aren't displayed when the parent stage isn't?
Example application:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class Main extends Application {
public static void run(String[] args) {
launch(args);
}
@Override
public void start(Stage stage) {
Button button1 = new Button("CREATE 2 ALERTS");
button1.setOnAction(event -> {
createAlert("First alert", stage, 300, 300);
createAlert("Second alert", stage, 500, 100);
});
StackPane root = new StackPane(button1);
Scene scene = new Scene(root);
stage.setScene(scene);
stage.setFullScreen(true);
stage.show();
}
private void createAlert(String text, Stage parentStage, int width, int height) {
Alert alert = new Alert(Alert.AlertType.INFORMATION);
alert.setHeaderText("");
alert.setContentText(text);
alert.initOwner(parentStage);
alert.getDialogPane().setPrefWidth(width);
alert.getDialogPane().setPrefHeight(height);
alert.show();
}
}
The problem has been replicated with two Windows 10 v10.0 machines, with java v1.8.0_161 javafx v8.0.161 and java v16.0.1 javafx v16

