Reputation: 1983
Is there such thing as a FloatField in java fx. I need to be able to write and edit floats. So I tested it using strings. But setCellProperty doesn't support floats
TableColumn<Dish, Float> costCol = new TableColumn<>("Price");
costCol.setCellValueFactory(new PropertyValueFactory<Dish, Float>("cost"));
costCol.setCellFactory(TextFieldTableCell.<Dish>forTableColumn());
Upvotes: 1
Views: 906
Reputation: 209553
The generic type for the TextFieldTableCell.forTableColumn()
method is the column type (Float
in this case), not the table type.
Assuming your Dish
class has a costProperty()
method returning the appropriate type, your code will work if you provide a converter to the forTableColumn
method:
costCol.setCellFactory(TextFieldTableCell.forTableColumn(new FloatStringConverter()));
(In Java 8, the complier will infer the correct generic type in the code above; if you want to be explicit you would do TextFieldTableCell<Float>.forTableColumn(...)
.)
Upvotes: 2