Hi,
switching from Swing to JFX 8, I am trying to find out how to do something I would normally do in a super-simple ListCellRenderer, i.e. customize the String displayed for an item. I tried this:
ComboBox<Integer> combo = new ComboBox<>();
combo.getItems().addAll(1, 2, 3);
combo.setCellFactory(new Callback<ListView<Integer>, ListCell<Integer>>() {
@Override
public ListCell<Integer> call(ListView<Integer> param) {
return new ListCell<Integer>(){
@Override
protected void updateItem(Integer item, boolean empty) {
if(item != null)
setText("#" + item);
}
};
}
});
However, when I do this, the customized String is not used for the selected Item (rather the standard toString() value of the item). Apart from that it is no longer selectable using the mouse (I submitted a bug report for this at https://javafx-jira.kenai.com/browse/RT-37445) but that is not really the point of my question.
What am I missing? Is this not the way to do it? Anything else I have to do to make sure the selected item is also rendered using the custom cell or is there a different mechanism for this?
Thanks,
Robert