Java JComboBox Selection selectComboBoxItem(JComboBox jComboBox, String name)

Here you can find the source of selectComboBoxItem(JComboBox jComboBox, String name)

Description

select Combo Box Item

License

Apache License

Declaration

public static void selectComboBoxItem(JComboBox jComboBox, String name) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import javax.swing.*;
import com.google.common.base.Optional;

public class Main {
    public static void selectComboBoxItem(JComboBox jComboBox, String name) {
        Optional itemToSelect = Optional.absent();
        for (int i = 0; i < jComboBox.getItemCount(); i++) {
            final Object item = jComboBox.getItemAt(i);
            if (name.equals(item.toString())) {
                itemToSelect = Optional.of(item);
            }/*from w ww.ja  v  a  2 s. com*/
        }
        if (itemToSelect.isPresent())
            jComboBox.setSelectedItem(itemToSelect.get());
    }
}

Related

  1. getSelectedItem(Object combo)
  2. getSelectedName(JComboBox comboBox)
  3. getSelectedString(JComboBox jcb)
  4. getTypedSelectedItemFromCombo(JComboBox combo)
  5. safeSelectFirst(JComboBox cb)
  6. selectStringInList(String string, JComboBox list)
  7. selectWithoutNotifyingListeners(JComboBox comboBox, int selectedIndex)
  8. setComboSelection(JComboBox cb, String sel)
  9. setComboxSelectItem(JComboBox cb, String s)