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);
}
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);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.