title: Need help using JFileChooser to import entire folder into JList in NetBeans
body: <p>I'm in the middle of creating a small program. I'm a bit of a noob when it       comes to programming and I just starting playing with the NetBeans GUI builder to help out a friend with his code. So far what happens is: </p>
  
  <ol>
  <li>JFrame pops up with a non-editable text field, button, JList, and empty panel. </li>
  <li>User clicks button, and it prompts them to select a directory. </li>
  <li>Once the user selects the directory, the program will load all files from this folder (eventually I'll set it to only allow .jpg). </li>
  <li><p>The program will then display the directory in the text field and place the names of these files in the JList. </p>
  
  <p>PROBLEM: 
  I'm having trouble with 4. I've been trying forever to get this thing to run. I've     gotten it to display the directory correctly. But I can't seem to get the JList to load the   file names from a file array. Here's some code if anyone can help. 
  <em>NOTE</em>: I have already declared a DefaulListModel named listModel outside of this buttons action event. The code isn't generating any errors but the JList remains empty after I click load. 
  text field -> directory 
  button -> jButton1 
  file chooser -> fc 
  string array of file names -> fileNames 
  file array of -> selectedFiles 
  JList -> fileList </p>
  
  <p>Thanks in advance! :)</p>
  
  <pre><code>private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
  JFileChooser fc = new JFileChooser(); 
  fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
  fc.showOpenDialog(null);
  File[] selectedFiles = fc.getSelectedFiles();
  directory.setText(fc.getSelectedFile().getAbsolutePath()); //this displays the path of the selected folder in the text field
  
  selectedFiles = fc.getSelectedFiles();        
  //this loop puts the files in the fileList... at least it should
  for(int i = 0; i &lt; selectedFiles.length; i++){
      listModel.addElement(selectedFiles[i]);
              }
  
  
  }
  </code></pre></li>
  </ol>