Java Utililty Methods JComboBox Model

List of utility methods to do JComboBox Model

Description

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

Method

voidaddItem(DefaultComboBoxModel model, String elem)
add Item
model.addElement(elem);
voidaddItems(DefaultComboBoxModel comboBox, Iterable items)
add Items
for (Object item : items) {
    comboBox.addElement(item);
booleancomboBoxContains(DefaultComboBoxModel model, Object obj)
Checks to see if a JComboBox contains an object.
for (int i = 0; i < model.getSize(); i++) {
    if (obj.equals(model.getElementAt(i))) {
        return true;
return false;
VectorconvertDefaultComboBoxModelToVector(DefaultComboBoxModel model)
convert Default Combo Box Model To Vector
Vector v = new Vector();
for (int i = 0; i < model.getSize(); i++) {
    v.add(model.getElementAt(i));
return v;
ComboBoxModelgenerateComboModel(Object[] values)
generate Combo Model
DefaultComboBoxModel model = new DefaultComboBoxModel(values);
return model;
DefaultComboBoxModelgenerateInsertWhereComboBoxModel(String label)
generate Insert Where Combo Box Model
Vector<String> values = new Vector<String>();
values.add(label);
values.add(ADD_AT_BEGINING);
values.add(ADD_ABOVE_SELECTION);
values.add(ADD_BELOW_SELECTION);
values.add(ADD_AT_END);
return new DefaultComboBoxModel(values);
ListgetComboModelList(ComboBoxModel model)
Return a List of Objects from a ComboBoxModel
ArrayList<Object> list = new ArrayList<Object>();
for (int i = 0; i < model.getSize(); i++) {
    list.add(model.getElementAt(i));
return list;
DefaultComboBoxModelgetNewDefaultComboBoxModel(ArrayList itemsToStream)
Creates a new Default Combo Box Model from the ArrayList if items
DefaultComboBoxModel newModel = new DefaultComboBoxModel();
itemsToStream.stream().forEach((c) -> {
    newModel.addElement(c);
});
return newModel;
ObjectgetSelectedItemfromModel(Object combo)
get Selected Itemfrom Model
return ((ComboBoxModel) combo).getSelectedItem();
booleanhasDataChanged(List newDatasets, ComboBoxModel currentModel)
Checks whether the data has changed and the model needs updating.
boolean result;
int i;
Set<String> setDatasets;
Set<String> setModel;
setDatasets = new HashSet<>(newDatasets);
setModel = new HashSet<>();
for (i = 0; i < currentModel.getSize(); i++)
    setModel.add(currentModel.getElementAt(i));
...