A JComboBox is a compact mechanism for selecting from a small number of options. The options are displayed when the user clicks on the combo box. If it is made editable the user can also enter text that is not supplied as one of the options.
String[] items = new String[] { "item 1", "item 2", "item 3", "item 4" }; JComboBox comboBox = new JComboBox(items);
Send a JComboBox a setEditable(true)
message if you want the
user to be able to type in an item.
Otherwise, the user can only select items in the drop-down list.
Describe model and model access methods.
If your code is not sending setSelectedItem() messages to a combo box then you can handle its responses with either an action listener or an item listener.
comboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { code to implement response to item selection. } });
comboBox.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { code to implement response to item selection. } });