Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set an Alert to be always on top?

Lets say I have a simple alert.

Alert a = new Alert(AlertType.NONE);

CustomLabel lbl = new CustomLabel("Testing");
CustomButton ok = new CustomButton("OK");
FlowPane fp = new FlowPane(); 
fp.getChildren().addAll(lbl,ok);

alert.getDialogPane().setContent(fp);
alert.initStyle(StageStyle.TRANSPARENT);

Then I would like this to make this alert always on top of whatever screen I am showing, how do I do it?

Setting the stage of my main page to.

mainStage.setAlwaysOnTop(false); //does not work

Both my main and alert are to be on the same thread.

Meaning, on running my main, it will check for something then pop up the alert if something is not right.

like image 877
Ronaldo Avatar asked Jan 04 '17 10:01

Ronaldo


1 Answers

Set your main stage to be always on top:

mainStage.setAlwaysOnTop(true);

Then set your main stage to be owner of Alert dialog:

a.initOwner(mainStage);

If main stage is owner of alert dialog, then alert will always be on top of main stage.

like image 122
MBec Avatar answered Oct 15 '22 08:10

MBec