Hi,
If you want to aware about the use of JComboBox class of java, then please go through the following example of JComboBox class:
Code:
import javax.swing.JComboBox;
import javax.swing.JTextArea;
public class EditComboBoxDM {
public static void main(String args[]) {
String labels1[] = { "A", "B", "C", "D","E", "F", "G", "H","I", "J" };
JFrame frame1 = new JFrame("Editable JComboBox");
frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container contentPane = frame1.getContentPane();
final JComboBox comboBox1 = new JComboBox(labels);
comboBox1.setMaximumRowCount(5);
comboBox1.setEditable(true);
contentPane.add(comboBox1, BorderLayout.NORTH);
final JTextArea textArea1 = new JTextArea();
JScrollPane scrollPane = new JScrollPane(textArea1);
contentPane.add(scrollPane, BorderLayout.CENTER);
ActionListener actionListener = new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
textArea1.append("Selected: " + comboBox1.getSelectedItem());
textArea1.append(", Position: " + comboBox1.getSelectedIndex());
textArea1.append(System.getProperty("line.separator"));
}
};
comboBox1.addActionListener(actionListener);
frame1.setSize(400, 200);
frame1.setVisible(true);
}
}
Bookmarks