JavaFX IntegerProperty unbind

Description

JavaFX IntegerProperty unbind

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

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

        // Create a binding: sum = x + y 
        NumberBinding sum = x.add(y); //  w w  w  . ja  v a2 s .  co  m
        
        // Bind z to x + y 
        z.bind(x.add(y)); 
        
        z.unbind(); 
        
        System.out.println("After creating sum:"); 
        System.out.println("sum.isValid(): " + sum.isValid()); 

        // Let us get the value of sum, so it computes its value and 
        // becomes valid 
        int value = sum.intValue(); 

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

        // Change the value of x 
        x.set(250); 

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

        // Get the value of sum again 
        value = sum.intValue(); 

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



PreviousNext

Related