Bidirectional Binding Example : binding « JavaFX « Java






Bidirectional Binding Example

 

import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;

public class Main {
    public static void main(String[] args) {
        StringProperty prop1 = new SimpleStringProperty("");
        StringProperty prop2 = new SimpleStringProperty("");

        prop2.bindBidirectional(prop1);

        System.out.println("prop1.isBound() = " + prop1.isBound());
        System.out.println("prop2.isBound() = " + prop2.isBound());

        prop1.set("asdf");
        System.out.println(prop2.get());

        prop2.set(prop2.get() );
        System.out.println(prop1.get());
    }
}

   
  








Related examples in the same category

1.Create custom binding by subclassing DoubleBinding
2.Bind and unbind
3.Createn conditional binding with When
4.Binding Group translateY Property