JComboBox: addItem(Object o) : JComboBox « javax.swing « Java by API






JComboBox: addItem(Object o)

  
import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import javax.swing.Icon;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class MainClass extends JPanel implements ItemListener {
  public MainClass() {
      JComboBox jc = new JComboBox(); 
      jc.addItem("France"); 
      jc.addItem("Germany"); 
      jc.addItem("Italy"); 
      jc.addItem("Japan"); 
      jc.addItemListener(this); 
      add(jc); 
  }

  public void itemStateChanged(ItemEvent ie) {
      String s = (String)ie.getItem(); 
      System.out.println(s); 
  }

  public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.getContentPane().add(new MainClass());

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(200, 200);
    frame.setVisible(true);
  }

}

           
         
    
  








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: addItemListener(ItemListener lis)
7.JComboBox: addPopupMenuListener(PopupMenuListener l)
8.JComboBox: getActionMap()
9.JComboBox: getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
10.JComboBox: getItemAt(int index)
11.JComboBox: getItemCount()
12.JComboBox: getKeySelectionManager()
13.JComboBox: getSelectedIndex()
14.JComboBox: getSelectedItem()
15.JComboBox: insertItemAt(Object anObject, int index)
16.JComboBox: isPopupVisible()
17.JComboBox: removeAllItems()
18.JComboBox: removeItemAt(int anIndex)
19.JComboBox: setEditor(ComboBoxEditor anEditor)
20.JComboBox: setKeySelectionManager(KeySelectionManager aManager)
21.JComboBox: setRenderer(ListCellRenderer aRenderer)
22.JComboBox: setEditable(boolean b)
23.JComboBox: setMaximumRowCount(int count)
24.JComboBox: setSelectedIndex(int anIndex)
25.JComboBox: setSelectedItem(Object anObject)
26.JComboBox: setUI(ComboBoxUI ui)