Java – dynamically add projects to jcombobox
•
Java
Vector combo@R_119_2419@Items = new Vector();
Vector combo@R_119_2419@Items = new Vector(); DefaultCombo@R_119_2419@Model model; // Combo@R_119_2419@ Items have gotten from Data Base initially. model = new DefaultCombo@R_119_2419@Model(Combo@R_119_2419@Items); JCombo@R_119_2419@ @R_119_2419@ = new JCombo@R_119_2419@(model);
I add this combo box to the panel If I add some items directly to the database, I want to display the newly added items in the combo box
When I debug, I can see combo@R_119_2419 @Item, but these values will not appear in my combo box
How do I add these newly added values to the combo box without closing the panel?
Solution
How to use Combo@R_119_2419 @Model? Something like this
JFrame frame = new JFrame("Combo @R_119_2419@ Demo"); frame.setDefaultCloSEOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(200,200); frame.setLayout(new FlowLayout()); Vector combo@R_119_2419@Items=new Vector(); combo@R_119_2419@Items.add("A"); combo@R_119_2419@Items.add("B"); combo@R_119_2419@Items.add("C"); combo@R_119_2419@Items.add("D"); combo@R_119_2419@Items.add("E"); final DefaultCombo@R_119_2419@Model model = new DefaultCombo@R_119_2419@Model(combo@R_119_2419@Items); JCombo@R_119_2419@ combo@R_119_2419@ = new JCombo@R_119_2419@(model); frame.add(combo@R_119_2419@); JButton button = new JButton("Add new element in combo @R_119_2419@"); frame.add(button); button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { model.addElement("F"); } }); frame.setVisible(true);
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码