Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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);
} 
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
420 views
Welcome To Ask or Share your Answers For Others

1 Answer

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);
}              

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...