Java JComboBox Value getInt(JComboBox combo)

Here you can find the source of getInt(JComboBox combo)

Description

get Int

License

Open Source License

Declaration

public static int getInt(JComboBox combo) 

Method Source Code

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

import javax.swing.JComboBox;

import javax.swing.JSpinner;

public class Main {
    public static int getInt(JComboBox combo) {
        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) {
                    try {
                        rv = Integer.parseInt(s.trim());
                    } catch (NumberFormatException ex) {
                    }//from   ww w .  j av a2s.  c  om
                }
            }
        }
        return rv;
    }

    public static int getInt(JSpinner spinner) {
        int rv = 0;
        Object o = spinner.getValue();
        if (o != null) {
            if (o instanceof Number) {
                rv = ((Number) o).intValue();
            }
        }
        return rv;
    }
}

Related

  1. createStandardCombo(String[] values)
  2. fillValue(Vector vtData, int iComboIndex, int iVectorIndex, JComboBox cbo, Vector vt, boolean bClear, boolean bHaveNull)
  3. getCmbValue(JComboBox cmb)
  4. getDouble(javax.swing.JComboBox input)
  5. getIfHasValue(Object val, JComboBox cb)
  6. IsComboBoxModified(JComboBox comboBox, Object originalValue)
  7. replaceContents(JComboBox combob, Object[] values)
  8. savePrefs(Preferences prefs, String prefKey, JComboBox combo, String newValidValue)
  9. setComboBoxIndex(final JComboBox aComboBox, final int aIndex)