-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
jfx24
-
generic
-
generic
A DESCRIPTION OF THE PROBLEM :
In JavaFX, the InvalidationListener added to properties is notified inconsistently.
Looking at EXAMPLE ONE, changing the value of a StringProperty, which itself is the property of a TextField, will notify the InvalidationListener every time the value changes.
Looking at EXAMPLE TWO, changing the value of a StringProperty, which is created as SimpleStringProperty, will notify the InvalidationListener only at the first change and after StringProperty.get() has been called. This is utterly confusing and should be considered a bug, since the only difference for the user is that one StringProperty is part of the TextField, the other is not.
////// EXAMPLE ONE
TextField tf = new TextField();
StringProperty sp = tf.textProperty();
sp.addListener(_ -> System.out.println("invalid") );
sp.set("One"); // prints "invalid"
sp.set("Two"); // prints "invalid"
sp.set("Three"); // prints "invalid"
sp.get();
out("Four"); // prints "invalid"
out("Five"); // prints "invalid"
out("Six"); // prints "invalid"
////// EXAMPLE ONE
////// EXAMPLE TWO
StringProperty sp = new SimpleStringProperty();
sp.addListener(_ -> System.out.println("invalid") );
sp.set("One"); // prints "invalid"
sp.set("Two"); // does not print anything
sp.set("Three"); // does not print anything
sp.get();
sp.set("Four"); // prints "invalid"
sp.set("Five"); // does not print anything
sp.set("Six"); // does not print anything
////// EXAMPLE TWO
In JavaFX, the InvalidationListener added to properties is notified inconsistently.
Looking at EXAMPLE ONE, changing the value of a StringProperty, which itself is the property of a TextField, will notify the InvalidationListener every time the value changes.
Looking at EXAMPLE TWO, changing the value of a StringProperty, which is created as SimpleStringProperty, will notify the InvalidationListener only at the first change and after StringProperty.get() has been called. This is utterly confusing and should be considered a bug, since the only difference for the user is that one StringProperty is part of the TextField, the other is not.
////// EXAMPLE ONE
TextField tf = new TextField();
StringProperty sp = tf.textProperty();
sp.addListener(_ -> System.out.println("invalid") );
sp.set("One"); // prints "invalid"
sp.set("Two"); // prints "invalid"
sp.set("Three"); // prints "invalid"
sp.get();
out("Four"); // prints "invalid"
out("Five"); // prints "invalid"
out("Six"); // prints "invalid"
////// EXAMPLE ONE
////// EXAMPLE TWO
StringProperty sp = new SimpleStringProperty();
sp.addListener(_ -> System.out.println("invalid") );
sp.set("One"); // prints "invalid"
sp.set("Two"); // does not print anything
sp.set("Three"); // does not print anything
sp.get();
sp.set("Four"); // prints "invalid"
sp.set("Five"); // does not print anything
sp.set("Six"); // does not print anything
////// EXAMPLE TWO
- duplicates
-
JDK-8369084 Inconsistent handling of InvalidationListener notifications
-
- Closed
-