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

Focus change listener is triggered twice

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 8
    • javafx
    • jdk1.8.0 b85

      To reproduce run the app and push 'Tab' several times.
      You will notice that when focus goes from the rectangle to the text
      the rectangle will fire change event.

      import javafx.application.Application;
      import javafx.beans.value.ChangeListener;
      import javafx.beans.value.ObservableValue;
      import javafx.scene.Scene;
      import javafx.scene.layout.VBox;
      import javafx.scene.paint.Color;
      import javafx.scene.shape.Rectangle;
      import javafx.scene.text.Text;
      import javafx.stage.Stage;

      /**
       * @author alexandr_kirov
       */
      public class NewClass extends Application {

          @Override
          public void start(Stage stage) throws Exception {

              Text text = new Text("text");
              text.setFocusTraversable(true);

              Rectangle r = new Rectangle(100, 100, 100, 100);
              r.setFill(Color.ALICEBLUE);
              r.setFocusTraversable(true);

              text.focusedProperty().addListener(new ChangeListener<Boolean>() {

                  @Override
                  public void changed(ObservableValue<? extends Boolean> ov, Boolean t, Boolean t1) {
                      System.out.println("Text focused.");
                  }
              });

              r.focusedProperty().addListener(new ChangeListener<Boolean>() {

                  @Override
                  public void changed(ObservableValue<? extends Boolean> ov, Boolean t, Boolean t1) {
                      System.out.println("Rectangle focused.");
                  }
              });

              VBox vb = new VBox();
              vb.getChildren().addAll(r, text);

              Scene scene = new Scene(vb, 300, 300);
              stage.setScene(scene);
              stage.show();
          }

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

            jgiles Jonathan Giles
            dzinkevi Dmitry Zinkevich (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: