}
private void testNonEditable(TestHarness harness)
{
JComboBox cb = new JComboBox();
BasicComboBoxUI ui = new BasicComboBoxUI();
cb.setUI(ui);
int additionalHeight = 2; // margin? border?
int additionalWidth = 2;
FontMetrics fm = cb.getFontMetrics(cb.getFont());
// the following width calculation is a guess. We know the value
// depends on the font size, and that it is relatively small, so after
// trying out a few candidates this one seems to give the right result
int width = fm.charWidth(' ') + additionalWidth;
int height = fm.getHeight() + additionalHeight;
harness.check(ui.getPreferredSize(cb),
new Dimension(width + height, height));
// the width is the display width plus the button width and
// the button width is equal to 'height'
cb.setModel(new DefaultComboBoxModel(new Object[] {"X"}));
width = fm.charWidth('X') + additionalWidth;
harness.check(ui.getPreferredSize(cb),
new Dimension(width + height, height));
cb.setModel(new DefaultComboBoxModel(new Object[] {null}));
harness.check(ui.getPreferredSize(cb).height, height);
cb.setModel(new DefaultComboBoxModel(new Object[] {""}));
harness.check(ui.getPreferredSize(cb).height, height);
cb.setPrototypeDisplayValue("XX");
width = fm.stringWidth("XX") + additionalWidth;
harness.check(ui.getPreferredSize(cb),
new Dimension(width + height, height));
}