I have made this:
private JComboBox vehicleType = new JComboBox();
DefaultComboBoxModel<Class> dcbm = new DefaultComboBoxModel<Class>(
new Class[] {Truck.class, Trailer.class, RoadTractor.class, SemiTrailer.class, Van.class, Car.class})
{
@Override
public String getSelectedItem() {
return ((Class<?>)super.getSelectedItem()).getSimpleName();
}
};
And I have obtained this:

How you can see, the selected item show his simple class name, but in the list... doesn't. How I can make this?
JComboBoxuses thetoString()method to get the label, you can override the behavior by implementing aListCellRenderer.Also if you use this method you should remove the override of
getSelectedItem()in your model as it will interfere with the renderer.