例子1(没有对数据库操作):
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.plaf.basic.BasicComboBoxRenderer;
public class ComboBoxItem extends JFrame implements ActionListener {
public ComboBoxItem() {
Vector model = new Vector();
model.addElement(new Item(1, "car"));
model.addElement(new Item(2, "plane"));
model.addElement(new Item(3, "train"));
model.addElement(new Item(4, "boat"));
JComboBox comboBox;
// Easiest approach is to just override toString() method
// of the Item class
comboBox = new JComboBox(model);
// comboBox.setDragEnabled(true);
comboBox.addActionListener(this);
getContentPane().add(comboBox, BorderLayout.NORTH);
// Most flexible approach is to create a custom render
// to diplay the Item data
comboBox = new JComboBox(model);
// comboBox.setDragEn