Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8089397

Closing and APPLICATION_MODAL stage can cause a window other than its owner to be brought to the front


    • Type: Bug
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 8u20
    • Fix Version/s: tbd
    • Component/s: javafx
    • Labels:
    • Environment:

      Java 8u20 b22, OS X 10.9.4


      This is very similar to but RT-34611 and could be considered a duplicate but I wanted to highlight another result of the issue. If an APPLICATION_MODAL stage is shown with an owner that is not the last opened window then when it closes a the last opened window will be brought to the front rather than the closed window's owner.

      This is a worse result than the flicker mentioned in RT-34611. Essentially it seems that when the modal stage closes all the other opened windows are brought to the front in the order they were shown which essentially changes the z order the user has left his windows in and means that the owner of the closed stage will often not be in the front.

      This behaviour can be observed in both Windows and OS X. In Linux the correct window ends up on top (the closed window's owner) but the window's z order is still reset when the application modal stage is closed.

      I have modified the test class so that all the windows can show an "owned" application modal dialog.

      Run the test class:

      1. Click on the title bar of the 3rd window to bring it to the front.

      2. Click on the "Dialog..." button.

      3. Click on the "Close" button to close this application modal stage.

      4. Notice that the last opened window labelled "4" is brought to the front.

      If you click around more to reorder the stages differently you will notice that whenever you close one of the "dialogs" the stages will be reorder into the order they were shown.

      ******************************************* Test Class **********************************************
      import javafx.application.Application;
      import javafx.event.ActionEvent;
      import javafx.event.EventHandler;
      import javafx.geometry.Pos;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.layout.Region;
      import javafx.scene.layout.StackPane;
      import javafx.scene.layout.VBox;
      import javafx.scene.text.Text;
      import javafx.stage.Modality;
      import javafx.stage.Stage;

      public class ModalityTest extends Application {
         private int numStages_ = 0;

         public void start(final Stage primaryStage) throws Exception {

            double x = 0;
            double y = 0;
            for (int i = 0; i < 3; i++) {
               Stage stage = new Stage();
               if ( x != 0 ) {
                  stage.setX(x + 50);
                  stage.setY(y + 50);
               x = stage.getX();
               y = stage.getY();

            primaryStage.setX(x + 50);
            primaryStage.setY(y + 50);
         private void buildAndShow( Stage stage ) {
            Button button = new Button("Dialog...");
            button.setOnAction(new EventHandler<ActionEvent>() {
               public void handle(ActionEvent event) {
                  final Stage dialog = new Stage();
                  Button b = new Button("Close");
                  b.setOnAction(new EventHandler<ActionEvent>() {
                     public void handle(ActionEvent event) {
                  dialog.setScene(new Scene(new StackPane(b), 100, 50));
                  dialog.setX(stage.getX() + 100);
                  dialog.setY(stage.getY() + 50);
            Text text = new Text("" + numStages_);
            text.setStyle("-fx-font-size: 3.0em;");
            VBox box = new VBox(20, text, button);
            box.setMaxSize(Region.USE_PREF_SIZE, Region.USE_PREF_SIZE);
            stage.setScene(new Scene(new StackPane(box), 400, 300));


         public static void main(String[] args) throws Exception {




            • Assignee:
              csmithjfx Charles Smith (Inactive)
            • Votes:
              0 Vote for this issue
              3 Start watching this issue


              • Created: