Java tutorial
<p>The following code shows how to create an invalidationListener to be registered with a property.As the property'svalue changes,the invalidated()method will be invoked.</p> <myPreCode> import javafx.beans.InvalidationListener; import javafx.beans.Observable; import javafx.beans.property.SimpleIntegerProperty; public class Main { public static void main(String[] args) { SimpleIntegerProperty xProperty = new SimpleIntegerProperty(0); // Adding a invalidation listener (anonymous inner class) xProperty.addListener(new InvalidationListener() { @Override public void invalidated(Observable o) { System.out.println(o.toString()); } }); // Adding a invalidation listener (lambda expression) xProperty.addListener((Observable o) -> { System.out.println(o.toString()); }); } }</myPreCode> <p> The difference between a ChangeListener and an invalidationListener.</p><UL><LI> Using a ChangeListener we will get the Observable (ObservableValue), the old value, and the new value</LI> <LI>Using the invalidationListener only gets the Observable object (property)</LI> <LI></LI> </UL> ===