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

Mouse handlers doesn't work after modal stage closed

XMLWordPrintable

    • x86_64
    • linux_ubuntu

      ADDITIONAL SYSTEM INFORMATION :
      Ubuntu 22.04 (no issue on Windows 10 / latest MacOS)

      A DESCRIPTION OF THE PROBLEM :
      On linux, after modal stage is closed, focus is returned to primary stage, but event handlers (like mouse hovering) doesn't work.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. launch app
      2. click on button to open modal window
      3. *After clicking to button move mouse a little left/right (to not hovering over modal window)*
      4. await for timer to tick and modal stage is closed
      5. hover over button - no printlns executed

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      same behavior as on Windows and MacOS: mouse events delivered to primary stage
      ACTUAL -
      mouse events aren't delivered to primary stage

      ---------- BEGIN SOURCE ----------
      import javafx.application.Application;
      import javafx.application.Platform;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.layout.StackPane;
      import javafx.stage.Modality;
      import javafx.stage.Stage;

      import java.util.Timer;
      import java.util.TimerTask;

      class TestApplication extends Application {
          @Override
          public void start(Stage primaryStage) {
              var timer = new Timer();
              primaryStage.setTitle("Primary stage");
              var button = new Button();
              button.setText("Open modal");
              button.setOnMouseEntered(event -> System.out.println("ENTER: " + event));
              button.setOnMouseExited(event -> System.out.println("EXIT: " + event));

              button.setOnAction(event -> {
                  System.out.println("ACTION: " + event);

                  var modalStage = new Stage();
                  modalStage.setTitle("Modal stage");
                  modalStage.initModality(Modality.WINDOW_MODAL);
                  modalStage.initOwner(primaryStage);
                  modalStage.setScene(new Scene(new StackPane(), 100.0, 100.0));
                  modalStage.show();
                  timer.schedule(new TimerTask() {
                      @Override
                      public void run() {
                          System.out.println("TIMED OUT!");
                          Platform.runLater(modalStage::close);
                      }
                  }, 2000);
              });
              primaryStage.setScene(new Scene(new StackPane(button), 500.0, 500.0));
              primaryStage.show();
          }

          public static void main(String[] args) {
              launch(args);
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      1. use Modality.NONE - not fully a workaround, as behavior is different
      2. move mouse out of window and return it back after modal stage is closed
      3. click into window after modal stage is closed

      FREQUENCY : always


            pnarayanaswa Praveen Narayanaswamy
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: