title: Java/Swing: Why is my JFileChooser opening twice?
body: <p>So I have created a Java GUI application, I have a main form, and I run this class PathBrowser by clicking a jbutton, The JFileChooser runs twice though, I have tried adding the opendialog from my mainform so I can have the same logo on the window.</p>
  
  <p>Here's my code: </p>
  
  <pre><code>public class PathBrowser {
  public static String filepath = null;
  public static void main(String[] args)
  {
  
      JButton select = new JButton();
      JFileChooser browse = new JFileChooser();
      //add the icon of main form for JFileChooser
      //OPENS TWICE?! Error
      browse.showOpenDialog(MainForm.frame);
  
      //if blank goes to user/documents. Unsure about other OSes
      browse.setCurrentDirectory(new java.io.File("C:/"));
      browse.setDialogTitle("Browse Folder");
      browse.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
      //when clicked open (approve option)
      if (browse.showOpenDialog(select) == JFileChooser.APPROVE_OPTION){
          //folder has peen selected
          MainForm.selfolder = true;
          //add the path to the string filepath
          filepath = (browse.getSelectedFile().getAbsolutePath());
          System.out.println("The path for the server is: "+browse.getSelectedFile().getAbsolutePath());
          //add the information to the textarea
          MainForm.textArea.setText("The path for the server is: "+browse.getSelectedFile().getAbsolutePath());
      }
  
  }
  
  }
  </code></pre>
  
  <p>Thanks</p>