如何使用ComboBoxModel?像这样…
Jframe frame = new Jframe("Combo Box Demo"); frame.setDefaultCloseOperation(Jframe.EXIT_ON_CLOSE); frame.setSize(200, 200); frame.setLayout(new FlowLayout()); Vector comboBoxItems=new Vector(); comboBoxItems.add("A"); comboBoxItems.add("B"); comboBoxItems.add("C"); comboBoxItems.add("D"); comboBoxItems.add("E"); final DefaultComboBoxModel model = new DefaultComboBoxModel(comboBoxItems); JComboBox comboBox = new JComboBox(model); frame.add(comboBox); JButton button = new JButton("Add new element in combo box"); frame.add(button); button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { model.addElement("F"); } }); frame.setVisible(true);
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)