Java JFileChooser directoryFetch(File starting)

Here you can find the source of directoryFetch(File starting)

Description

Creates a JFileChooser that allows user to select multiple directories.

License

Open Source License

Parameter

Parameter Description
starting Starting directory. If you want to use the user's home directory, I suggest using <tt>System.getProperty("user.home")</tt>

Exception

Parameter Description
IllegalArgumentException If the solitary param is non-existent or not a directory.

Return

A list of Files representing directories the user selected.

Declaration

public static File[] directoryFetch(File starting) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.File;

import javax.swing.JFileChooser;

public class Main {
    /**// w w  w .  j av a 2  s.co m
     * Creates a JFileChooser that allows user to select multiple directories. Program is exited if
     * user cancels/closes the dialog box.
     * 
     * @param starting Starting directory. If you want to use the user's home directory, I suggest
     *           using <tt>System.getProperty("user.home")</tt>
     * @return A list of Files representing directories the user selected.
     * @throws IllegalArgumentException If the solitary param is non-existent or not a directory.
     */
    public static File[] directoryFetch(File starting) {
        if (!starting.isDirectory()) // idiot proofing
            throw new IllegalArgumentException("Specified directory does not exist or is not a directory");

        JFileChooser fc = new JFileChooser(starting);
        fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        fc.setDialogTitle("select directories");
        fc.setMultiSelectionEnabled(true);

        if (fc.showOpenDialog(null) != JFileChooser.APPROVE_OPTION)
            System.exit(0);

        return fc.getSelectedFiles();
    }
}

Related

  1. createJFileChooserWithExistenceChecking()
  2. createJFileChooserWithOverwritePrompting()
  3. createOpenFileChooser(String title, String dir, Component parent, FileFilter filter)
  4. createReportFileChooser(String curDir, File defaultReportFile)
  5. createUserDefinedProfileFileChooser()
  6. exportFile(JFileChooser fileChooser, String contents)
  7. fileChooser()
  8. getChoiceFileFromUser()
  9. getDir(String title, String initDir, boolean allowFiles, Component parent)