I am new to JavaFX and I built a tableview in JavaFX, and here is the example code:
TableView<Person> table = new TableView<>();
table.setEditable(true);
final TableColumn<Person, String>nameCol = new TableColumn<>("Name");
nameCol.setCellValueFactory(new PropertyValueFactory<>("name"));
After I adding a list into the table, everything works just fine.
But when I add these code after the NameCol:
nameCol.setCellFactory(param -> new XCell());
public class XCell extends TableCell<Person, String> {
@Override
protected void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
setStyle(empty ? null : "-fx-font-weight: bold; -fx-alignment: center");
//...
}
}
Then, the data from nameColumn went missing. But when I comment that code:
//nameCol.setCellFactory(param -> new XCell());
All the data just went back again.
It is so wired that I can't find out what is wrong with that.
I'll appreciate if anyone could explain what is happened and fix it.