title: Setting JList values with for loop
body: <p>I have an array of strings that I would like to dynamically apply as the items in a JList. The items in the array will change frequently, so the Jlist model will need to change as well. This is an example of what I have now:</p>
  
  <pre><code>    listAvail = new JList();
      listAvail.setBorder(
              new TitledBorder(null, "", TitledBorder.LEADING, TitledBorder.TOP, null, null));
      listAvail.setModel(new AbstractListModel()
      {
          String[] values = new String[] { "Feature 1", "Feature 2", "Feature 3", "Feature 4",
                  "Feature 5" };
  
          public int getSize()
          {
              return values.length;
          }
  
          public Object getElementAt(int index)
          {
              return values[index];
          }
      });
      scrollPane.setViewportView(listAvail);
  </code></pre>
  
  <p>I want to replace that code with something like this:</p>
  
  <pre><code>    listAvail = new JList();
      listAvail.setBorder(
              new TitledBorder(null, "", TitledBorder.LEADING, TitledBorder.TOP, null, null));
      listAvail.setModel(new AbstractListModel()
      {
  
          String[] values = new String[5];
  
          for (int i = 0; i &lt; 5; i++)
          {
              values[i] = "Feature" + i;
          }
  
  
          public int getSize()
          {
              return values.length;
          }
  
          public Object getElementAt(int index)
          {
              return values[index];
          }
      });
      scrollPane.setViewportView(listAvail);
  </code></pre>
  
  <p>What am I doing wrong?</p>