Example usage for javax.swing JComboBox getPreferredSize

List of usage examples for javax.swing JComboBox getPreferredSize

Introduction

In this page you can find the example usage for javax.swing JComboBox getPreferredSize.

Prototype

@Transient
public Dimension getPreferredSize() 

Source Link

Document

If the preferredSize has been set to a non-null value just returns it.

Usage

From source file:gg.pistol.sweeper.gui.component.DecoratedPanel.java

/**
 * Helper factory method for creating a language selector that provides functionality to change the locale.
 *
 * @param width/*  w  w w. ja v a2  s .  co m*/
 *         the preferred width of the component in pixels
 * @return the newly created language selector
 */
protected JComboBox createLanguageSelector(int width) {
    Preconditions.checkArgument(width >= 0);
    final JComboBox<SupportedLocale> selector = new JComboBox(i18n.getSupportedLocales().toArray());
    selector.setSelectedItem(i18n.getCurrentSupportedLocale());
    selector.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            i18n.setLocale((SupportedLocale) selector.getSelectedItem());
        }
    });
    int height = selector.getPreferredSize().height;
    selector.setMinimumSize(new Dimension(width, height));
    selector.setMaximumSize(new Dimension(width, height));
    selector.setPreferredSize(new Dimension(width, height));
    selector.setMaximumRowCount(i18n.getSupportedLocales().size());
    selector.setComponentOrientation(ComponentOrientation.getOrientation(i18n.getLocale()));
    return selector;
}