import java.awt.BorderLayout;
import java.awt.Container;
import javax.swing.JComboBox;
import javax.swing.JFrame;
public class ComboBoxSample {
public static void main(String args[]) {
String labels[] = { "A", "B", "C", "D","E", "F", "G", "H","I", "J" };
String title = (args.length == 0 ? "Example JComboBox" : args[0]);
JFrame frame = new JFrame(title);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container contentpane = frame.getContentPane();
JComboBox comboBox1 = new JComboBox(labels);
comboBox1.setMaximumRowCount(5);
contentpane.add(comboBox1, BorderLayout.NORTH);
JComboBox comboBox2 = new JComboBox(labels);
comboBox2.setEditable(true);
contentpane.add(comboBox2, BorderLayout.SOUTH);
frame.setSize(300, 200);
frame.setVisible(true);
}
}
|