Testing Invalidation Events for JavaFX Properties - Java JavaFX

Java examples for JavaFX:Action

Description

Testing Invalidation Events for JavaFX Properties

Demo Code

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

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

    counter.addListener(Main::invalidated);

    System.out.println("Before changing the counter value-1");
    counter.set(101);/* ww  w. j a  v  a 2s .c  om*/
    System.out.println("After changing the counter value-1");

    System.out.println("Before changing the counter value-2");
    counter.set(102);
    System.out.println("After changing the counter value-2");

    int value = counter.get();
    System.out.println("Counter value = " + value);

    System.out.println();
    System.out.println("Before changing the counter value-3");
    counter.set(102);
    System.out.println("After changing the counter value-3");

    System.out.println();
    System.out.println("Before changing the counter value-4");
    counter.set(103);
    System.out.println("After changing the counter value-4");
  }

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

Related Tutorials