4

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

coder
  • 8,346
  • 16
  • 39
  • 53
John Szatmari
  • 375
  • 4
  • 11

1 Answers1

7

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.

Michael Berry
  • 70,193
  • 21
  • 157
  • 216