{
e.printStackTrace();
}
JComboBox cb = new JComboBox();
cb.setEditable(true);
MyBasicComboBoxUI ui = new MyBasicComboBoxUI();
cb.setUI(ui);
JTextField tf = (JTextField) cb.getEditor().getEditorComponent();
int columns = tf.getColumns();
FontMetrics fm = cb.getFontMetrics(cb.getFont());
// for an editable JComboBox the display size is calculated from the
// preferred size of the JTextField it seems, or the prototype display
// value in some cases...
int width = fm.charWidth('m') * columns;
int height = fm.getHeight() + 2; // the 2 seems to be a fixed margin
// not sure why the width here needs + 1..
harness.check(ui.getDisplaySize(), new Dimension(width + 1, height));
cb.addItem("ABC");
harness.check(ui.getDisplaySize(), new Dimension(width, height));
cb.addItem("A longer item");
harness.check(ui.getDisplaySize(), new Dimension(width, height));
cb.setPrototypeDisplayValue("Prototype");
harness.check(ui.getDisplaySize(), new Dimension(width, height));
cb.setPrototypeDisplayValue("Long Prototype Display Value");
width = fm.stringWidth("Long Prototype Display Value") + 2;
harness.check(ui.getDisplaySize(), new Dimension(width, height));
// restore a sane look and feel
try
{
UIManager.setLookAndFeel(new MetalLookAndFeel());