Here you can find the source of getIfHasValue(Object val, JComboBox cb)
private static Object getIfHasValue(Object val, JComboBox cb)
//package com.java2s; import javax.swing.*; public class Main { private static Object getIfHasValue(Object val, JComboBox cb) { if (val == null) { return null; }/* w w w . j a v a 2s.c o m*/ 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; } }