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

Focus change listener is triggered twice

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Not an Issue
    • Affects Version/s: 8
    • Fix Version/s: None
    • Component/s: javafx
    • Labels:
    • Environment:

      jdk1.8.0 b85

      Description

      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);
          }
      }

        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated:
              Resolved:
              Imported: