Java Utililty Methods JComboBox

List of utility methods to do JComboBox

Description

The list of methods to do JComboBox are organized into topic(s).

Method

voidaddHorizontalScrollBar(JComboBox box)
add Horizontal Scroll Bar
if (box.getItemCount() == 0)
    return;
Object comp = box.getUI().getAccessibleChild(box, 0);
if (!(comp instanceof JPopupMenu)) {
    return;
JPopupMenu popup = (JPopupMenu) comp;
int n = popup.getComponentCount();
...
voidaddToCombo(JComboBox combo, Iterator it)
This method automatically adds the contents of a data structured refered to by an iterator to a JComboBox instance.
while (it.hasNext()) {
    combo.addItem(it.next());
voidaddToComboBox(JComboBox list, Object object)
add To Combo Box
ComboBoxModel model = list.getModel();
if (model == null) {
    model = new DefaultComboBoxModel();
    list.setModel(model);
;
if (model instanceof DefaultComboBoxModel) {
    DefaultComboBoxModel listModel = (DefaultComboBoxModel) model;
...
voidadjustComboBoxHeight(JComboBox comboBox)
adjust Combo Box Height
if (comboBox == null) {
    return;
Font font = (Font) UIManager.getDefaults().get("ComboBox.font");
if (comboBox != null && font != null) {
    Dimension uiSize = comboBox.getUI().getPreferredSize(comboBox);
    FontMetrics fontMetrics = comboBox.getFontMetrics(font);
    int height = fontMetrics.getHeight() + fontMetrics.getDescent() + 3;
...
voidadjustPopupWidth(JComboBox comboBox)
Adjust popup for combo box, so that horizontal scrollbar will not display.
voidadjustSize(JComboBox comboBox)
adjust Size
comboBox.setPreferredSize(new Dimension(0, FIELD_HEIGHT));
voidapplyDefaultProperties(final JComboBox comp)
Sets default background and foreground color as well as a default font for the specified component.
if (comp == null) {
    return;
applyProperties(comp, "ComboBox.background", 
        "ComboBox.foreground", 
        "ComboBox.font"); 
voidCargarComboBox(JComboBox cb, List lista)
Cargar Combo Box
Vector<T> v = new Vector<T>();
for (T p : lista) {
    v.add(p);
cb.setModel(new DefaultComboBoxModel<T>(v));
voidcheckJComboBoxNotEmpty(javax.swing.JComboBox combo, javax.swing.JLabel promptName, ArrayList errors)
check J Combo Box Not Empty
if (!isJComboBoxNotEmpty(combo))
    errors.add(promptName.getText());
voidcomboBoxScroll(JComboBox box)
combo Box Scroll
if (box == null) {
    return;
Object comp = box.getUI().getAccessibleChild(box, 0);
if (!(comp instanceof JPopupMenu)) {
    return;
JPopupMenu popup = (JPopupMenu) comp;
...