JComboBox: setSelectedItem(Object anObject) : JComboBox « javax.swing « Java by API






JComboBox: setSelectedItem(Object anObject)

  
import javax.swing.JComboBox;

public class Main {
  public static void main(String[] argv) throws Exception {
    String[] items = { "item1", "item2" };
    JComboBox cb = new JComboBox(items);

    Object obj = cb.getSelectedItem(); 

    cb.setSelectedItem("item2");
    obj = cb.getSelectedItem(); 

    cb.setSelectedItem("item3");
    obj = cb.getSelectedItem(); 
  }
}

   
    
  








Related examples in the same category

1.implements JComboBox.KeySelectionManager
2.new JComboBox()
3.new JComboBox(ComboBoxModel aModel)
4.new JComboBox(Vector items)
5.JComboBox: addActionListener(ActionListener lis)
6.JComboBox: addItem(Object o)
7.JComboBox: addItemListener(ItemListener lis)
8.JComboBox: addPopupMenuListener(PopupMenuListener l)
9.JComboBox: getActionMap()
10.JComboBox: getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
11.JComboBox: getItemAt(int index)
12.JComboBox: getItemCount()
13.JComboBox: getKeySelectionManager()
14.JComboBox: getSelectedIndex()
15.JComboBox: getSelectedItem()
16.JComboBox: insertItemAt(Object anObject, int index)
17.JComboBox: isPopupVisible()
18.JComboBox: removeAllItems()
19.JComboBox: removeItemAt(int anIndex)
20.JComboBox: setEditor(ComboBoxEditor anEditor)
21.JComboBox: setKeySelectionManager(KeySelectionManager aManager)
22.JComboBox: setRenderer(ListCellRenderer aRenderer)
23.JComboBox: setEditable(boolean b)
24.JComboBox: setMaximumRowCount(int count)
25.JComboBox: setSelectedIndex(int anIndex)
26.JComboBox: setUI(ComboBoxUI ui)