JComboBox cb = new JComboBox();
MyMetalComboBoxUI ui = new MyMetalComboBoxUI();
cb.setUI(ui);
Insets insets = ui.getArrowButton().getInsets();
Insets comboInsets = cb.getInsets();
MetalComboBoxButton b = (MetalComboBoxButton) ui.getArrowButton();
Dimension displaySize = ui.getDisplaySize();
int width = displaySize.width + insets.left + 2 * insets.right
+ comboInsets.left + comboInsets.right
+ b.getComboIcon().getIconWidth();
int height = displaySize.height + comboInsets.top + comboInsets.bottom
+ insets.top + insets.bottom;
harness.check(ui.getPreferredSize(cb), new Dimension(width, 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"}));
displaySize = ui.getDisplaySize();
width = displaySize.width + insets.left + 2 * insets.right
+ comboInsets.left + comboInsets.right
+ b.getComboIcon().getIconWidth();
height = displaySize.height + comboInsets.top + comboInsets.bottom
+ insets.top + insets.bottom;
harness.check(ui.getPreferredSize(cb), new Dimension(width, height));
cb.setPrototypeDisplayValue("XX");
displaySize = ui.getDisplaySize();
width = displaySize.width + insets.left + 2 * insets.right
+ comboInsets.left + comboInsets.right
+ b.getComboIcon().getIconWidth();
height = displaySize.height + comboInsets.top + comboInsets.bottom
+ insets.top + insets.bottom;
harness.check(ui.getPreferredSize(cb), new Dimension(width, height));
}