Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

1 Answer
Samual Sam

To get directories from JFileChoose, use the mode setFileSelectionMode −

JFileChooser file = new JFileChooser();
file.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

The following is an example to get Directories from JFileChooser −

Example

import javax.swing.JFileChooser;
public class SwingDemo {
   public static void main(String[] args) {
      JFileChooser file = new JFileChooser(); file.setMultiSelectionEnabled(false);
         file.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
      int res = file.showOpenDialog(null);
      if (res == JFileChooser.APPROVE_OPTION) { java.io.File f = file.getSelectedFile();
         System.err.println(f.getPath());
      }
   }
}

Output

Advertisements

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.