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

[Popup] Popup "steals" focus, when hiding the popup (regression)

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P3
    • 8u20
    • 8, 8u5, 8u20
    • javafx
    • Windows 7

    Description

      Since JavaFX 8, hiding a popup causes that the owner window is focused, when the popup gets hidden.
      It used to work well in JavaFX 2.2!

      This is troublesome, because it then "steals" the focus from another window, where the user might work in.

      The Notifications control from ControlsFX is affected by this bug as well.

      The following app starts the primary stage ("Main Stage"), and periodically opens and hides popups (primary stage is owner).

      Then, if you focus the other stage (title: "Focus me!!"), the primary stage will get focused again, when the popup is hidden, which disturbs the user in his work (e.g. when he's typing in a TextArea).

      A popup should not focus its owner stage, when hiding.


      import javafx.animation.PauseTransition;
      import javafx.application.Application;
      import javafx.application.Platform;
      import javafx.event.ActionEvent;
      import javafx.event.EventHandler;
      import javafx.scene.Scene;
      import javafx.scene.control.Label;
      import javafx.scene.control.TextArea;
      import javafx.stage.Popup;
      import javafx.stage.Stage;
      import javafx.util.Duration;

      import java.util.concurrent.Executors;
      import java.util.concurrent.ScheduledExecutorService;
      import java.util.concurrent.TimeUnit;

      public class TestApp4 extends Application {
          public static void main(String[] args) throws Exception {
              launch(args);
          }


          public void start(final Stage stage) throws Exception {

              ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
              scheduledExecutorService.scheduleAtFixedRate(new Runnable() {
                  @Override
                  public void run() {
                      Platform.runLater(new Runnable() {
                          @Override
                          public void run() {
      // This is from ControlsFX project. Same problem here.
      // Notifications.create()
      // .title("Title Text")
      // .text("Hello World 0!")
      // .showWarning();

                              final Popup popup = new Popup();
                              Label label = new Label("POPUP CONTENT");
                              label.setStyle("-fx-background-color: red");
                              popup.getContent().addAll(label);
                              popup.show(stage);

                              final PauseTransition pauseTransition = new PauseTransition(Duration.seconds(2));
                              pauseTransition.setOnFinished(new EventHandler<ActionEvent>() {
                                  @Override
                                  public void handle(ActionEvent actionEvent) {
                                      popup.hide();
                                  }
                              });
                              pauseTransition.playFromStart();
                          }
                      });
                  }
              }, 0, 3, TimeUnit.SECONDS);

              Stage subStage = new Stage();
              subStage.setTitle("Focus me!!");
              TextArea textArea = new TextArea();
              textArea.setPromptText("Write here and get annoyed, when focus gets lost soon.");
              Scene scene = new Scene(textArea, 300, 300);
              subStage.setScene(scene);
              subStage.show();

              stage.setScene(new Scene(new Label("Main Stage"), 300, 300));
              stage.show();
          }
      }

      Attachments

        Issue Links

          Activity

            People

              anthony Anthony Petrov (Inactive)
              cschudtjfx Christian Schudt (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported: