3 Replies Latest reply: Dec 20, 2012 7:46 AM by 965397 RSS

    Will  javafx.beans.binding.Bindings ever support BigDecimal?

    965397
      Hello,
      I am just learning javafx.
      I just read the javadoc of javafx.beans.binding.Bindings and am surprised that it does not support BigDecimal or BigInteger in any way?
      Forexample multiply,add,...

      Will this ever be supported or is there another API I don't know about?

      Greetings
      John
        • 1. Re: Will  javafx.beans.binding.Bindings ever support BigDecimal?
          jsmith
          Log your feature request under the Runtime project at: http://javafx-jira.kenai.com

          Solutions can also be contributed to http://openjdk.java.net/projects/openjfx/ or http://jfxtras.org/
          • 2. Re: Will  javafx.beans.binding.Bindings ever support BigDecimal?
            Cobra Ice
            One solution is to use SimpleObjectProperty.


            Bigdecimal is an imutable object.
            So after doing a calculation on an object you have to use the new object in any case.
            It goes something like this:
            BigDecimal val100 = new BigDecimal(100);
            BigDecimal val = new BigDecimal(100);
            
            val = val.add(val100); // Creates a new BigDecimal with a value of 200
            val = val.add(val100); // Creates a new BigDecimal with a value of 300
            val = val.add(val100); // Creates a new BigDecimal with a value of 400
            val = val.add(val100); // Creates a new BigDecimal with a value of 500
            To make this BigDecimal a property with all the benefits of a property is simple:
            BigDecimal val100 = new BigDecimal(100);
            SimpleObjectProperty<BigDecimal> val = new SimpleObjectProperty(new BigDecimal(100));
            
            val.set(    val.get().add(val100)    ); // Creates a new BigDecimalProperty with a value of 200
            val.set(    val.get().add(val100)    ); // Creates a new BigDecimalProperty with a value of 300
            val.set(    val.get().add(val100)    ); // Creates a new BigDecimalProperty with a value of 400
            val.set(    val.get().add(val100)    ); // Creates a new BigDecimalProperty with a value of 500
            All that is needed is the get to get the property value to do calculations on and at the end a set to replace the normal "=" statement in the previous peace of code.

            Hope this is useful.

            SimpleObjectProperty is so useful that I have even created custom list properties that fires change listeners even if an item in the list changed, which is extremely useful in a lot of situations.

            Edited by: Cobra Ice on Dec 20, 2012 1:16 AM
            • 3. Re: Will  javafx.beans.binding.Bindings ever support BigDecimal?
              965397
              Thanks a lot for your answer! helps a lot!