My parent stage "stage1" is opening child stage "stage2" and i have set child stage's modality as below.
stage2.initModality(Modality.APPLICATION_MODAL);
Now when i open stage2 from stage1, stage1 is appears behind stage2 that is expected, but when i press "Ctrl+Tab" key, control switches to 3rd paty applicaton for example "Outlook", then I again press "Ctrl+Tab" key, it returns to our main applicaton and it shows stage2 but stage1 appears hidden. My expectation is that stage1 should be hidden behind stage2.
Any help is greatly appriciated.
It is because Stage2.getOwner() == null
is true. Your expectation is the way it works, when it is false
. so to solve your problem do this
Stage2.initOwner(Stage1);
ediit
here is some demo
@Override
public void start(Stage stage) {
Pane p = new Pane();
p.setStyle("-fx-background-color: red");
stage.setTitle("I AM THE PARENT");
Scene scene = new Scene(p);
stage.setWidth(600);
stage.setHeight(600);
stage.setScene(scene);
stage.show();
Stage s = new Stage(StageStyle.DECORATED);
s.initModality(Modality.APPLICATION_MODAL);
p = new Pane();
p.setStyle("-fx-background-color: yellow");
s.setScene(new Scene(p,150,150));
//s.initOwner(stage); //with this commented it wont work
s.show();
}
Also you will notice that when your press CTRL + TAB
the windows popup only shows your second window STAGE2
, that is who he knows of, because its has not parent, but when it has owner is shows only the owner
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