I want to force an Alert to be on top of other applications. Alerts seems to be lacking a setAlwaysOnTop function.
I have seen this post: JavaFX 2.2 Stage always on top.
I have tried:
Does anyone know how to achieve this?
Edit: I am using Java 8.
Let say I have safari opened, and it is being focused. I want to bring the Alert to the top of the screen, in front of safari, when I call its showAndWait() function.
Alert alert = new Alert(Alert.AlertType.WARNING, "I Warn You!", ButtonType.OK, ButtonType.CANCEL);
Stage stage = (Stage) alert.getDialogPane().getScene().getWindow();
stage.setAlwaysOnTop(true);
stage.toFront(); // not sure if necessary
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With