title: updating DefaultListModel on another thread
body: <p>I have a program that need to update the content of <code>JList</code>, which is <code>DefaultListModel</code> on another thread. Since the number of contents may change from time to time, so I just clear all content and add new content into <code>DefaultListModel</code> when updating. But seems I ran into an issue that <code>JFrame</code> starts refreshing while my thread is doing update. I got exceptions like this </p>
  
  <pre><code>Exception in thread "AWT-EventQueue-0" 
  java.lang.ArrayIndexOutOfBoundsException: 3
  </code></pre>
  
  <p>Here is an <strong>example of the code</strong> </p>
  
  <pre><code>    DefaultListModel model;
      JList jList;
      JScrollPane jScrollPane;
  
      Thread thread;
      public Frame() {
          this.setTitle("ASM_SIMULATOR");
          this.setBounds(100, 100, 500, 500);
          this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          this.getContentPane().setLayout(null);
  
          model = new DefaultListModel();
          jList = new JList(model);
          jScrollPane = new JScrollPane(jList);
  
          jList.setBounds(50, 50, 300, 200);
          jScrollPane.setBounds(50, 50, 300, 200);
  
          this.getContentPane().add(jScrollPane);
  
          this.setVisible(true);
  
          thread = new Thread(new Runnable() {
              @Override
              public void run() {
                  while (true) {
  
                      makeData();
                      try {
                          Thread.sleep(200);
                      } catch (InterruptedException e) {
                          e.printStackTrace();
                      }
                  }
              }
  
          });
  
          thread.start();
      }
  
      public void makeData() {
          System.out.println("makeData()");
          model.clear();
  
          for (int i = 0; i &lt; 20; i++) {
              model.addElement((int) (Math.random() * 100));
          }
  
      }
  
      public static void main(String[] args) {
          new Frame();
  
      }
  </code></pre>