Java JComboBox Selection setComboxSelectItem(JComboBox cb, String s)

Here you can find the source of setComboxSelectItem(JComboBox cb, String s)

Description

set Combox Select Item

License

GNU General Public License

Declaration

public static boolean setComboxSelectItem(JComboBox cb, String s) 

Method Source Code

//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;
    }
}

Related

  1. safeSelectFirst(JComboBox cb)
  2. selectComboBoxItem(JComboBox jComboBox, String name)
  3. selectStringInList(String string, JComboBox list)
  4. selectWithoutNotifyingListeners(JComboBox comboBox, int selectedIndex)
  5. setComboSelection(JComboBox cb, String sel)
  6. setListData(final JComboBox box, final Collection items, final E selected)
  7. setSelectedHeadersaveFileTypeItem( JComboBox combo, int fileType)
  8. updateContents( @SuppressWarnings("rawtypes") JComboBox box, Object[] options, int selectedIndex)