Java JComboBox Model comboBoxContains(DefaultComboBoxModel model, Object obj)

Here you can find the source of comboBoxContains(DefaultComboBoxModel model, Object obj)

Description

Checks to see if a JComboBox contains an object.

License

Open Source License

Parameter

Parameter Description
model combo box to check
obj object to test for

Return

true or false

Declaration

public static boolean comboBoxContains(DefaultComboBoxModel model, Object obj) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import javax.swing.DefaultComboBoxModel;

public class Main {
    /**//from w w  w  . ja va  2 s. c om
     * Checks to see if a JComboBox contains an object.
     * @param model combo box to check
     * @param obj object to test for
     * @return true or false
     */
    public static boolean comboBoxContains(DefaultComboBoxModel model, Object obj) {
        for (int i = 0; i < model.getSize(); i++) {
            if (obj.equals(model.getElementAt(i))) {
                return true;
            }
        }
        return false;
    }
}

Related

  1. addItem(DefaultComboBoxModel model, String elem)
  2. addItems(DefaultComboBoxModel comboBox, Iterable items)
  3. convertDefaultComboBoxModelToVector( DefaultComboBoxModel model)
  4. generateComboModel(Object[] values)
  5. generateInsertWhereComboBoxModel(String label)
  6. getComboModelList(ComboBoxModel model)