JComboBox<String> choice = new JComboBox<String>();
choice.setBounds(20, 1, 81, 21);
choice.setFont(new Font("微软雅黑 Light", Font.PLAIN, 13));
choice.addItem("ID");
choice.addItem("商品名称");
frm_drop.getContentPane().add(choice);
choice.addItemListener(new ItemListener(){
public void itemStateChanged(ItemEvent e) {
Choice choice = (Choice) e.getItemSelectable();
switch (choice.getSelectedItem()) {
case "ID":
break;
case "商品名称":
break;
default:
break;
}
}
});
组件使用错误的,JComboBox是javafx中的组件,而Choice你导入的包是java.awt中的