title: JList showing empty lines in Java
body: <p>I have a following array:</p>
  
  <pre><code>static String[] nameData = new String[100];
  </code></pre>
  
  <p>And a <code>JList</code>, with displays the array's contents:</p>
  
  <pre><code>rightPanel.add(Box.createRigidArea(new Dimension(20, 20)));
  final JList list = new JList(nameData);
  list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  list.setLayoutOrientation(JList.VERTICAL);
  list.setVisibleRowCount(-1);
  JScrollPane listScroller = new JScrollPane(list);
  listScroller.setPreferredSize(new Dimension(250, 80));
  listScroller.setAlignmentX(LEFT_ALIGNMENT);
  rightPanel.add(listScroller);
  </code></pre>
  
  <p>But when for example only first slot in the array are filled and rest are with the value null, <code>JList</code> still displays them as an empty line and lets you select it (I have added an image below).</p>
  
  <p><img src="https://i.stack.imgur.com/je4NW.png" alt="7th element in array"></p>
  
  <p>This is how a 7th element in array would be selected, although I would like the <code>JList</code> only to display elements that have a value besides null.</p>