Reputation: 23
I have a tableview that has columns of types (SimpleStringProperty, SimpleIntegerProperty)
STRING1 STRING2 INTEGER1 INTEGER2
####### ####### ######## ########
a b 9 10
a c 9 12
b d 0 0
Now, in the 3rd row, the 3rd and 4th column have values as 0. The type of which is SimpleIntegerProperty.
I would like it if the 0s don't show up in the table and the cell appears empty. Can you please advice on how i may do this?
P.S: I am using property listeners for making an editable table. Strings are initialized to null and hence the table is blank but integers are getting initialized to 0.
Upvotes: 0
Views: 458
Reputation: 1861
You have to provide a TableCellFactory which returns your customized TableCell-Object. In the TableCell's updateItem()-method you can call setText() as suggested by Lukas Leitinger.
TableColumn columnInteger2 = new TableColumn("Integer2");
columnInteger2.setCellValueFactory(
new PropertyValueFactory<MyVo,String>("fieldInteger2"));
columnInteger2.setCellFactory(new Callback<TableColumn, TableCell>() {
@Override
public TableCell call(TableColumn tableColumn) {
return new TableCell<String, Integer>(){
@Override
protected void updateItem(Integer integer, boolean b) {
if (integer != null) {
super.setText(integer == 0?"":integer.toString());
}
}
};
}
});
Upvotes: 0
Reputation: 631
I think you have to extend from ListCell and override the updateItem method. In that method you have to check if the SimpleIntegerProperty equals 0 and probably call setText("") then.
Upvotes: 1