title: Adding elements to JList in Swing Java
body: <p>I have a function that executes when a button is clicked. Suppose there is a loop to add 1 to 10 to a <code>JList</code>. I add that data to <code>DefaultListModel</code>. It works perfectly and the numbers get added. Then I added a <code>Thread.sleep(1000)</code> within the loop. But the output is different. I wanted to add 1 element every second. But now it waits for 10secs and the add all 1 to 10 together at the end of 10th second. Am I wrong anywhere?</p>
  
  <pre><code>List processList = listNumbers.getSelectedValuesList();
  DefaultListModel resultList = new DefaultListModel();
  listResult.setModel(resultList);
  
  for (int i = 0; i &lt; processList.size(); i++) {
      resultList.addElement(String.valueOf(i));
      try {
          Thread.sleep(1000);
      }
      catch (InterruptedException ex) {
      }
  }
  </code></pre>