I have a list of employees whose names I need to render on a combo box for the user to select. The following code renders the names on the dropdown list, but when I select a name, the combo's displayed text contains the full POJO's identity, a string like "src.org.entities.Employee@449ac7ce"
cboEmployees.setCellFactory(new Callback<ListView<Employee>, ListCell<Employee>>()
{
@Override
public ListCell<Employee> call(ListView<Employee> p)
{
return new ListCell<Employee>()
{
@Override
protected void updateItem(Employee item, boolean empty) {
super.updateItem(item, empty);
if (item != null)
{
setText(item.getName());
}
}
};
}
});
Is there a way to make the displayed text renders the selected name as well without overriding the POJO's toString() method?