问题
i have created a Jcombobox and i have populated it from data base, i have a JList and i want every item i select in the combobox to be added on the JList. i'm new to java and i tried to solve the problem with this code but it's not working :
private void addelementActionPerformed(java.awt.event.ActionEvent evt) {
DefaultListModel liss = new DefaultListModel();
Object s = empcombo_s.getSelectedItem().toString();
for(int i =0; i<=1;i++) {
liss.add(i, s);
}
stagelist.setModel(liss);
}
回答1:
now this code is working properly :
DefaultListModel liss = new DefaultListModel();
private void addelementActionPerformed(java.awt.event.ActionEvent evt) {
String s = empcombo_s.getSelectedItem().toString();
liss.addElement(s);
stagelist.setModel(liss);
}
来源:https://stackoverflow.com/questions/31733667/add-selected-item-from-jcombobox-to-jlist