Using a Simple Binding in JavaFX - Java JavaFX

Java examples for JavaFX:Bindable Properties

Description

Using a Simple Binding in JavaFX

Demo Code

import javafx.beans.binding.NumberBinding;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleIntegerProperty;

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

    NumberBinding sum = x.add(y);/*from  w  w w.j av  a2  s  . c  o m*/

    System.out.println("After creating sum");
    System.out.println("sum.isValid(): " + sum.isValid());

    int value = sum.intValue();

    System.out.println("After requesting value");
    System.out.println("sum.isValid(): " + sum.isValid());
    System.out.println("sum = " + value);

    x.set(250);

    System.out.println("After changing x");
    System.out.println("sum.isValid(): " + sum.isValid());

    value = sum.intValue();

    System.out.println("After requesting value");
    System.out.println("sum.isValid(): " + sum.isValid());
    System.out.println("sum = " + value);
  }
}

Related Tutorials