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

TextFormatter.valueProperty().bindBidirectional does not really bind

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • 9
    • 8u45
    • javafx
    • None
    • Win 7 Pro SP1, JDK 8u45, 64 Bit

    • x86_64
    • windows_7

      The following code lines will not result in a working bidirectional binding:

      ObjectProperty<Integer> modelProperty = new SimpleObjectProperty<>();
      TextFormatter<Integer> t = (TextFormatter<Integer>) myTextField.textFormatterProperty().get();
      ObjectProperty<Integer> guiProperty = t.valueProperty();
      guiProperty.bindBidirectional(modelProperty);

      While this compiles and runs, when typing into the text field, the modelProperty will not fire any lilsteners.

      Now comes the strange thing. I do not use bindBidirectional but simply add two listeners:

      guiProperty.set(modelProperty.get());
      guiProperty.addListener((property, oldValue, newValue) -> modelProperty.set(newValue));
      modelProperty.addListener((property, oldValue, newValue) -> guiProperty.set(newValue));

      This DOES work: When typing in the TextField, all listeners registered with modelProperty DO FIRE.

      This is kind of weird, as typically one would think that bindBidirectional would actually do just that exact three lines under the hood...

            vadim Vadim Pakhnushev
            mkarg Markus Karg
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: