3 Replies Latest reply: Dec 7, 2011 2:39 PM by Knut Arne Vedaa RSS

    IntegerProperty implements ObservableValue<Number>

    Knut Arne Vedaa
      I think I may have found my first wtf in the JavaFX API: :)
      class IntegerProperty implements ObservableValue<Number>
      instead of
      class IntegerProperty implements ObservableValue<Integer>
      Now, I assume this has not been decided at random and that there is some rationale behind. I'm curious about what that is.

      However, it results in the following trivial problem:
      class Person(StringProperty name, IntegerProperty age)
      ...then in some TableView<Person>:
                  ageCol.setCellValueFactory(new Callback<CellDataFeatures<Person, Integer>, ObservableValue<Integer>>() {
                      public ObservableValue<Integer> call(CellDataFeatures<Person, Integer> p) {
                          return p.getValue().age;  // THIS DOESN'T WORK! 
                      }
                  });
      You'll have to change the return line to:
      return new ReadOnlyObjectWrapper<Integer>(p.getValue().age.getValue());
      Am I supposed to use
      ObjectProperty<Integer>
      in my data model instead of IntegerProperty?

      Edited by: Knut Arne Vedaa on Dec 4, 2011 7:41 AM