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...
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...