The parent phase is hidden when switching to a third-party window and switches back to the application phase

My parent stage "stage1" opens the child scene "stage2", and I installed the mod for the child stage, as shown below.

stage2.initModality(Modality.APPLICATION_MODAL); 

Now, when I open stage2 from stage 1, stage1 appears after scene2, which is expected, but when I press the Ctrl + Tab key, the control switches to the 3rd patch application, for example, Outlook, and then press Ctrl + Tab ", it goes back to our main applicate, and it shows stage2, but stage1 seems hidden. My expectation is that stage1 should be hidden behind the stage2.

Any help would be very helpful.

+7
java javafx modal-dialog
source share
1 answer

This is because Stage2.getOwner() == null true. Your expectation is how it works when it is false . so to solve your problem do it

 Stage2.initOwner(Stage1); 

ediit

here are some demos

 @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(); } 

You will also notice that when you press CTRL + TAB Windows popup only displays your second STAGE2 window, that is, the one he knows because he does not have a parent, but when he has an owner, only the owner is displayed

+5
source share

All Articles