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

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


    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 8, 8u5, 8u20
    • Fix Version/s: 8u20
    • Component/s: javafx
    • Labels:
    • Environment:

      Windows 7


      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 {

          public void start(final Stage stage) throws Exception {

              ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
              scheduledExecutorService.scheduleAtFixedRate(new Runnable() {
                  public void run() {
                      Platform.runLater(new Runnable() {
                          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");

                              final PauseTransition pauseTransition = new PauseTransition(Duration.seconds(2));
                              pauseTransition.setOnFinished(new EventHandler<ActionEvent>() {
                                  public void handle(ActionEvent actionEvent) {
              }, 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);

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


          Issue Links



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


                • Created: