BindingDemo.java

JavaFX introduces a new concept called binding property that enables a target object to be bound to a source object. If the value in the source object changes, the target property is also changed automatically. The target object is simply called a binding object or a binding property.

Command window output

C:\ece538\JavaFX\JavaPP\ch14>java BindingDemo
d1 is 2.0 and d2 is 2.0
d1 is 70.2 and d2 is 70.2


BindingDemo.java

import javafx.beans.property.DoubleProperty;
import javafx.beans.property.SimpleDoubleProperty;

public class BindingDemo {
  public static void main(String[] args) {       
    DoubleProperty d1 = new SimpleDoubleProperty(1);
    DoubleProperty d2 = new SimpleDoubleProperty(2);
    d1.bind(d2);
    System.out.println("d1 is " + d1.getValue() 
      + " and d2 is " + d2.getValue());
    d2.setValue(70.2);
    System.out.println("d1 is " + d1.getValue() 
      + " and d2 is " + d2.getValue());
  }
}


Maintained by John Loomis, updated Sat Feb 10 16:34:17 2018