This might be a dup - I can't find it exactly though - I'm basically simply trying to customize a JComboBox display by providing my own ListCellRenderer:
targetCombo = new JComboBox();
targetCombo .setRenderer(new BasicComboBoxRenderer(){
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus){
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (value != null){
MyObj myObj = (myObj)value;
setText(myObj.getName());
}
return this;
}
});
The component properly displays the name when I expand the JComboBox list. However, on item selection, the display reverts to the toString() value of myObj.
Am I missing something?