Search code examples
javaswingjcombobox

JComboBox.addItem for null objects


HI,

I have a JComboBox to which I'm adding my custom object items. But sometimes the object added are empty. So, when the comboBox has empty items in it, it collapses and becomes very thin. But once populated, becomes of noral height. Can somebody please suggest semething to keep the height of the JComboBox maintained even when no items or empty items added.

private final JComboBox comboField = new JComboBox (); comboField.removeAllItems(); comboField.addItem(getFirstConfig()); comboField.addItem(getSecConfig());

Thanks


Solution

  • Just added a check that if the options for the Jcombobox are null, then add an empty string "". This keeps the ComboBox from collapsing.