add To JComboBox Combo Box - Java Swing

Java examples for Swing:JComboBox

Description

add To JComboBox Combo Box

Demo Code


//package com.java2s;

import javax.swing.*;

public class Main {
    public static void addToComboBox(JComboBox list, Object object) {
        ComboBoxModel model = list.getModel();
        if (model == null) {
            model = new DefaultComboBoxModel();
            list.setModel(model);/*from   ww  w.  j a  va  2  s  . com*/
        }
        ;
        if (model instanceof DefaultComboBoxModel) {
            DefaultComboBoxModel listModel = (DefaultComboBoxModel) model;
            listModel.addElement(object);
        }
    }
}

Related Tutorials