Java JComboBox Value containsValue(JComboBox comboBox, String value)

Here you can find the source of containsValue(JComboBox comboBox, String value)

Description

contains Value

License

Open Source License

Parameter

Parameter Description
comboBox a parameter
value a parameter

Return

if the comboBox contains the specified value

Declaration

public static boolean containsValue(JComboBox comboBox, String value) 

Method Source Code


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

import javax.swing.ComboBoxModel;
import javax.swing.JComboBox;

public class Main {
    /**// w w  w .java  2 s.  c  o m
     * @param comboBox
     * @param value
     * @return if the comboBox contains the specified value
     */
    public static boolean containsValue(JComboBox comboBox, String value) {
        ComboBoxModel model = comboBox.getModel();
        int size = model.getSize();
        for (int i = 0; i < size; i++) {
            Object element = model.getElementAt(i);
            if (element.equals(value)) {
                return true;
            }
        }
        return false;
    }
}

Related

  1. createComboBox(ActionListener actionListener, Vector values, String command)
  2. createComboBox(final Preferences node, final String pref_name, final String[] options, final String default_value)
  3. createStandardCombo(String[] values)
  4. fillValue(Vector vtData, int iComboIndex, int iVectorIndex, JComboBox cbo, Vector vt, boolean bClear, boolean bHaveNull)