Here you can find the source of setComboxSelectItem(JComboBox cb, String s)
public static boolean setComboxSelectItem(JComboBox cb, String s)
//package com.java2s; /*/* w w w .ja va 2 s. c o m*/ * Copyright (C) 2015 University of Oregon * * You may distribute under the terms of either the GNU General Public * License or the Apache License, as specified in the LICENSE file. * * For more information, see the LICENSE file. */ import javax.swing.JComboBox; public class Main { public static boolean setComboxSelectItem(JComboBox cb, String s) { int num = cb.getItemCount(); if (s == null || num < 1) return false; String v = (String) cb.getSelectedItem(); if (v.equals(s)) return false; for (int i = 0; i < num; i++) { v = (String) cb.getItemAt(i); if (v.equals(s)) { cb.setSelectedIndex(i); return true; } } return false; } }