JavaFX IntegerProperty bind bidirectional

Description

JavaFX IntegerProperty bind bidirectional

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

public class Main {
  public static void main(String[] args) {
 // Create two properties called x and y 
    IntegerProperty x = new SimpleIntegerProperty(10); 
    IntegerProperty y = new SimpleIntegerProperty(20); 

    System.out.println("x:"+x.get());
    System.out.println("y:"+y.get());
    // Create bidirectional binding between x and y 
    x.bindBidirectional(y); //from  w ww .j  av  a  2 s .c  om
    System.out.println("x:"+x.get());
    System.out.println("y:"+y.get());
    // Now, both x and y are 20. The values and x and y are always the same when x or y changes. 

    // Remove the bidirectional binding between x and y 
    x.unbindBidirectional(y); 
    System.out.println("x:"+x.get());
    System.out.println("y:"+y.get());
    // Now, x and y maintain their values independent of each other. 
  }
}



PreviousNext

Related