synchronize property values of multiple objects with (bidirectional) binding (binding order, property initialisation)

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: P4
    • fx2.1
    • Affects Version/s: fx2.0.1
    • Component/s: javafx
    • Environment:

      windows 7, jdk 7, javafx 2.0.1

      I'd like to synchronize a value among multiple objects with bidirectional bindings. Example:
      {code}
      import javafx.beans.property.DoubleProperty;
      import javafx.beans.property.SimpleDoubleProperty;
       
      public class SandboxBindingDoubleProperties
      {
      public static void main(String[] args)
      {
      DoubleProperty doubleProperty1 = new SimpleDoubleProperty(1);
      DoubleProperty doubleProperty2 = new SimpleDoubleProperty(2);
      DoubleProperty doubleProperty3 = new SimpleDoubleProperty(3);

      doubleProperty1.bindBidirectional(doubleProperty2);
      doubleProperty2.bindBidirectional(doubleProperty3);
       
      doubleProperty1.set(4);
      System.out.println(doubleProperty1.doubleValue());
      System.out.println(doubleProperty2.doubleValue());
      System.out.println(doubleProperty3.doubleValue());
      doubleProperty2.set(5);
      System.out.println(doubleProperty1.doubleValue());
      System.out.println(doubleProperty2.doubleValue());
      System.out.println(doubleProperty3.doubleValue());
      doubleProperty3.set(6);
      System.out.println(doubleProperty1.doubleValue());
      System.out.println(doubleProperty2.doubleValue());
      System.out.println(doubleProperty3.doubleValue());
      }
      }
      {code}
      The output is:

      4.0
      3.0 <- error, should be 4.0
      3.0 <- error, should be 4.0
      5.0
      5.0
      5.0
      6.0
      6.0
      6.0

      A change in the binding order leads to the expected behaviour:
      {code}
      doubleProperty2.bindBidirectional(doubleProperty3);
      doubleProperty1.bindBidirectional(doubleProperty2);
      {code}
      4.0
      4.0
      4.0
      5.0
      5.0
      5.0
      6.0
      6.0
      6.0

      An additional but superfluous binding to the original example also leads to the expected behaviour:
      {code}
      doubleProperty1.bindBidirectional(doubleProperty2);
      doubleProperty2.bindBidirectional(doubleProperty3);
      doubleProperty3.bindBidirectional(doubleProperty1);
      {code}
      Starting with no-args constructors also leads to expected behaviour:
      {code}
      DoubleProperty doubleProperty1 = new SimpleDoubleProperty();
      DoubleProperty doubleProperty2 = new SimpleDoubleProperty();
      DoubleProperty doubleProperty3 = new SimpleDoubleProperty();
      {code}

            Assignee:
            Michael Heinrichs (Inactive)
            Reporter:
            J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: