if (!comboBox.isEditable())
if (comboBox.isEditable() && comboBox.getModel().getSize() == 0) return new Dimension(100, editor.getPreferredSize().height);  Dimension dim = new Dimension(); ListCellRenderer renderer = comboBox.getRenderer(); ComboBoxModel model = comboBox.getModel(); if (renderer != null && model.getSize() > 0)
  protected Dimension getDisplaySize()  {    if (!comboBox.isEditable())       {    Object prototype = comboBox.getPrototypeDisplayValue();    if (prototype != null)      {        // calculate result based on prototype        ListCellRenderer renderer = comboBox.getRenderer();        Component comp = renderer.getListCellRendererComponent(listBox,                 prototype, -1, false, false);        Dimension compSize = comp.getPreferredSize();        compSize.width += 2;  // add 1 pixel margin around area        compSize.height += 2;        return compSize;      }    else      {    ComboBoxModel model = comboBox.getModel();    int numItems = model.getSize();    // if combo box doesn't have any items then simply    // return its default size    if (numItems == 0)      {	displaySize = getDefaultSize();	return displaySize;      }    Dimension size = new Dimension(0, 0);    // ComboBox's display size should be equal to the     // size of the largest item in the combo box.     ListCellRenderer renderer = comboBox.getRenderer();    for (int i = 0; i < numItems; i++)      {        Object item = model.getElementAt(i);            Component comp = renderer.getListCellRendererComponent(listBox,                     item, -1, false, false);        Dimension compSize = comp.getPreferredSize();            if (compSize.width + 2 > size.width)              size.width = compSize.width + 2;            if (compSize.height + 2 > size.height)              size.height = compSize.height + 2;      }    displaySize = size;    return displaySize;  }  }    else // an editable combo,        {        Component comp = comboBox.getEditor().getEditorComponent();        Dimension prefSize = comp.getPreferredSize();        int width = prefSize.width;        int height = prefSize.height + 2;        Object prototype = comboBox.getPrototypeDisplayValue();        if (prototype != null)          {            FontMetrics fm = comboBox.getFontMetrics(comboBox.getFont());            width = Math.max(width, fm.stringWidth(prototype.toString()) + 2);          }        displaySize = new Dimension(width, height);        return displaySize;      }  }