title: Stack added items on JList
body: <p>I'm trying to transfer the selected items from a source JList and destination JList on button click. So what I did is this. </p>
  
  <pre><code>private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
          int index = AddSubjectsToCurriculum.getSelectedIndex();
          String selectedItemOnSourceList = AddSubjectsToCurriculum.getSelectedValue().toString(); 
          int x = 0;
  
          if(index &gt;= 0) // --if atleast 1 is selected
          {
              DefaultListModel dlm = new DefaultListModel(); //--declare a placeholder for items you will add
                  dlm.add(x++,selectedItemOnSourceList); // --add the selected item to dlm 
                  CurriculumSubjects.setModel(dlm); //--at this point item has been added already
              ((DefaultListModel)AddSubjectsToCurriculum.getModel()).remove(index); // --remove what was selected from source list
          }//end of if
      }
  </code></pre>
  
  <p>But everytime I click the button, it only adds the selected item from source list but never populates or updates the destination list with new elements added. How do I fix this? I need to setModel() everytime button is clicked but I need to be able to move forward to the next index on next button click.</p>
  
  <p>Only adds one and shows one element for every <code>&gt;</code> button click</p>
  
  <p><a href="https://i.stack.imgur.com/n9zAH.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/n9zAH.jpg" alt="enter image description here"></a></p>
  
  <p>I'd appreciate any help. Thanks. </p>