JavaFX Observable handle invalidate event

Description

JavaFX Observable handle invalidate event

import javafx.beans.Observable;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleIntegerProperty;

public class Main {
  public static void main(String[] args) {
    // Create a property
    IntegerProperty counter = new SimpleIntegerProperty(100);

    counter.addListener(Main::invalidated);

    System.out.println("A");
    counter.set(1);//from   ww  w.j a  va  2  s.  c o  m
    System.out.println("B");


    // Make the counter property valid by calling its get() method
    int value = counter.get();
    System.out.println("Counter value = " + value);

    // Try setting the same value
    System.out.println("C");
    counter.set(102);
    System.out.println("D");

  }

  public static void invalidated(Observable prop) {
    System.out.println("Counter is invalid.");
  }
}



PreviousNext

Related