JavaFX Properties in TableView

One somewhat strange part of the property API is that IntegerProperty implements ObservableValue<Number>, not ObservableValue<Integer>. So, somewhat counterintuitively, you need

TableColumn<Person, Number> ageColumn = new TableColumn<Person, Number>("Age");

As an aside, and I’m not sure if this causes problems, but it’s more usual to use int instead of Integer for the return type for the get method and the parameter type for the set method in your model class. These match the types for IntegerProperty.get() and IntegerProperty.set(...), so it just avoids some implicit auto (un)boxing.

Leave a Comment