|
This Example illustrates how to create the jcombobox in swing application. The output of the program and source code are given below:
Source Code of CreateComboBox.java
import java.util.Vector;
import javax.swing.JFrame;
import javax.swing.JComboBox;
import java.awt.BorderLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
public class CreateComboBox extends JFrame {
public CreateComboBox() {
super("ComboBox");
getContentPane().setLayout(new BorderLayout());
Vector cars = new Vector();
cars.addElement("Java");
cars.addElement("Applet");
cars.addElement("Swing");
getContentPane().add(new JComboBox(cars));
WindowListener wndCloser = new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
};
addWindowListener(wndCloser);
pack();
setVisible(true);
}
public static void main(String argv[]) {
new CreateComboBox();
}
} |
|
|