📅  最后修改于: 2022-03-11 14:52:27             🧑  作者: Mango
@FXML ComboBox cmbUserIds;
Callback, ListCell> cellFactory = new Callback, ListCell>() {
@Override
public ListCell call(ListView l) {
return new ListCell() {
@Override
protected void updateItem(User item, boolean empty) {
super.updateItem(item, empty);
if (item == null || empty) {
setGraphic(null);
} else {
setText(item.getId() + " " + item.getName());
}
}
} ;
}
}
// Just set the button cell here:
cmbUserIds.setButtonCell(cellFactory.call(null));
cmbUserIds.setCellFactory(cellFactory);