Java Utililty Methods JComboBox Value

List of utility methods to do JComboBox Value

Description

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

Method

booleancontainsValue(JComboBox comboBox, String value)
contains 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;
JComboBoxcreateComboBox(ActionListener actionListener, Vector values, String command)
create Combo Box
JComboBox combo = new JComboBox(values);
combo.setActionCommand(command);
if (actionListener != null) {
    combo.addActionListener(actionListener);
return combo;
JComboBoxcreateComboBox(final Preferences node, final String pref_name, final String[] options, final String default_value)
create Combo Box
final String[] interned_options = new String[options.length];
for (int i = 0; i < options.length; ++i) {
    interned_options[i] = options[i].intern();
default_value.intern();
final JComboBox combo_box = new JComboBox(interned_options);
final String current_stored_value = node.get(pref_name, default_value).intern();
combo_box.addActionListener(new ActionListener() {
...
JComboBoxcreateStandardCombo(String[] values)
create Standard Combo
JComboBox combo = new JComboBox(values);
FontMetrics fm = combo.getFontMetrics(combo.getFont());
combo.setPreferredSize(new Dimension(150, fm.getHeight()));
combo.setMinimumSize(new Dimension(75, fm.getHeight()));
return combo;
voidfillValue(Vector vtData, int iComboIndex, int iVectorIndex, JComboBox cbo, Vector vt, boolean bClear, boolean bHaveNull)
fill Value
if (bClear) {
    vt.clear();
    cbo.removeAllItems();
if (bHaveNull) {
    vt.addElement("");
    cbo.addItem("");
for (int iRowIndex = 0; iRowIndex < vtData.size(); iRowIndex++) {
    Vector vtResultRow = (Vector) vtData.elementAt(iRowIndex);
    vt.addElement(vtResultRow.elementAt(iVectorIndex));
    cbo.addItem(vtResultRow.elementAt(iComboIndex));
ObjectgetCmbValue(JComboBox cmb)
get Cmb Value
Object item = cmb.getSelectedItem();
if (item instanceof String) {
    return null;
} else {
    return item;
doublegetDouble(javax.swing.JComboBox input)
Get double from the JComboBox input
return new Double((String) (input.getSelectedItem())).doubleValue();
ObjectgetIfHasValue(Object val, JComboBox cb)
get If Has Value
if (val == null) {
    return null;
String vals = val.toString();
for (int i = 0; i < cb.getModel().getSize(); i++) {
    if (cb.getModel().getElementAt(i).toString().equals(vals)) {
        return val;
return null;
intgetInt(JComboBox combo)
get Int
int rv = 0;
Object o = combo.getSelectedItem();
if (o != null) {
    if (o instanceof Number) {
        rv = ((Number) o).intValue();
    } else {
        String s = o.toString();
        if (s != null) {
...
booleanIsComboBoxModified(JComboBox comboBox, Object originalValue)
Is Combo Box Modified
return (comboBox.getSelectedItem() != null ? !comboBox.getSelectedItem().equals(originalValue)
        : originalValue != null);