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

TextFormatter filter getting called for all components instead of one.

    Details

    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      generic

      Description

      A DESCRIPTION OF THE PROBLEM :
      TextFormatter filter is getting called for all components whenever a user focuses out of any component.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Click on any textfield from the program provided in the source code.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      1. Focus out should not call TextFormatter filter, because the text is not changed.
      2. Even if it is called, it should be called on the component from which focus is shifted out.
      ACTUAL -
      Getting notification of filter from all the components as below whenever focuses out from any element
      ===============================================
      Field 1 Has recieved change notification.
      Field 2 Has recieved change notification.
      Field 3 Has recieved change notification.

      ---------- BEGIN SOURCE ----------
      import java.util.function.UnaryOperator;

      import javafx.application.Application;
      import static javafx.application.Application.launch;
      import javafx.geometry.Insets;
      import javafx.scene.Scene;
      import javafx.scene.control.TextField;
      import javafx.scene.control.TextFormatter;
      import javafx.scene.layout.StackPane;
      import javafx.scene.layout.VBox;
      import javafx.stage.Stage;

      public class SingleIndRun6 extends Application {

          public TextField txtFldObjA;
          public TextField txtFldObjB;
          public TextField txtFldObjC;


          private TextField createFixedPrefixTextField(String prefix, String id) {
              TextField txtFldObj = new TextField(prefix);
              txtFldObj.setId(id);

              UnaryOperator<TextFormatter.Change> filter = c -> {
                  System.out.println(id+" Has recieved change notification.");
                  return c;
              };

              txtFldObj.setTextFormatter(new TextFormatter<>(filter));
              return txtFldObj;
          }

          @Override
          public void start(Stage primaryStage) {
              txtFldObjA = createFixedPrefixTextField("$ ","Field 1");
              txtFldObjB = createFixedPrefixTextField("R ","Field 2");
              txtFldObjC = createFixedPrefixTextField("P ","Field 3");
              
              VBox box = new VBox(10);
              box.setPadding(new Insets(10,10,10,10));
              
              box.getChildren().addAll(txtFldObjA, txtFldObjB, txtFldObjC);
              
              StackPane root = new StackPane(box);
              Scene scene = new Scene(root, 400, 400);
              primaryStage.setScene(scene);
              primaryStage.show();
          }

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

      FREQUENCY : always


        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                aghaisas Ajit Ghaisas
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated: