Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaFX Alert on current screen

I have a problem using the Alert class in order to make a popup when pressing a certain button, for example when trying to change a variable, a popup would show up asking "Are you sure you want to change that?" and you could click on "Yes" or "No". The problem appears in a multi-screen setup, specifically when the main application is not on the main screen. If you click on the button that triggers this Alert, then the popup will show up on the main screen, not on the current one. Is there a way to force it to show up on the current screen? Thank you.

This is an example of the popup:

Popup Example

enter image description here

like image 293
John Szatmari Avatar asked Oct 28 '25 09:10

John Szatmari


1 Answers

Use:

alert.initModality(Modality.APPLICATION_MODAL);
alert.initOwner(stage);

...before calling show() or showAndWait() on the alert, where stage is the stage you want the alert to appear over.

like image 127
Michael Berry Avatar answered Oct 31 '25 05:10

Michael Berry