John Szatmari
John Szatmari

Reputation: 395

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

Upvotes: 4

Views: 1327

Answers (1)

Michael Berry
Michael Berry

Reputation: 72284

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.

Upvotes: 7

Related Questions