Cannot add to a JList when list is added to a JScrollPane
<p>I wrote a program which select files and adds them to a JList. The program works fine, and the code to add the files to the list is like this:</p>

<pre><code>JPanel pane;
File newFile[];
static List&lt;File&gt; files = new ArrayList&lt;File&gt;();
static DefaultListModel&lt;File&gt; listModel = new DefaultListModel&lt;&gt;();
JList&lt;File&gt; fileList = new JList&lt;&gt;(listModel);

JPanel listPane = new JPanel();
pane.add(listPane, BorderLayout.CENTER);
listPane.setBackground(Color.LIGHT_GRAY);
listPane.setBorder(new EmptyBorder(0, 20, 0, 0));
listPane.setLayout(new BorderLayout());
listPane.add(fileList);
}
void getFile() {
    final JFileChooser fc = new JFileChooser();
    fc.setDialogTitle("Select File...");
    fc.setApproveButtonText("Select");
    fc.setMultiSelectionEnabled(true);
    int returnVal = fc.showOpenDialog(pane);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        newFile = fc.getSelectedFiles();
    }
}
void setFile() {
    int i = 0;
    while (i &lt; newFile.length) {
        files.add(newFile[i]);
        listModel.addElement(newFile[i]);
        i++;
    }
}
</code></pre>

<p>This is the base code for selecting and adding the files. So now I want to have  a scrollbar on the pane, so I modified it to a JScrollPane like this:</p>

<pre><code>JScrollPane listPane = new JScrollPane();
pane.add(listPane, BorderLayout.CENTER);
listPane.setBackground(Color.LIGHT_GRAY);
listPane.setBorder(new EmptyBorder(0, 20, 0, 0));
listPane.setViewportView(fileList);
listPane.add(fileList);
}
</code></pre>

<p>So everything compiles without errors, but nothing is added to the JScrollPane. It is my understanding that a JScrollPane can be used like a regular JPanel, except it will have scrollbars when overflowed. Is there something about JScrollPanes that I am missing here?</p>