Java JFileChooser askForFolder(File rootDir)

Here you can find the source of askForFolder(File rootDir)

Description

ask For Folder

License

Open Source License

Declaration

public static File askForFolder(File rootDir) 

Method Source Code


//package com.java2s;
/*/* w  ww. jav  a  2  s  . c om*/
 * Copyright (C) 2015 Christopher Collin Hall
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.io.File;

import javax.swing.JFileChooser;

public class Main {
    public static File askForFolder(File rootDir) {
        JFileChooser jfc = new JFileChooser(rootDir);
        jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        int action = jfc.showOpenDialog(null);
        if (action == JFileChooser.CANCEL_OPTION)
            return null;
        return jfc.getSelectedFile();
    }

    public static File askForFolder(String title, File rootDir) {
        JFileChooser jfc = new JFileChooser(rootDir);
        jfc.setDialogTitle(title);
        jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        int action = jfc.showOpenDialog(null);
        if (action == JFileChooser.CANCEL_OPTION)
            return null;
        return jfc.getSelectedFile();
    }
}

Related

  1. askForFile(String title, File rootDir)
  2. askForFiles(File rootDir)
  3. askUserForFileURL(Component aParent, boolean bOpen)
  4. browseFileForList(DefaultListModel listModel, JFileChooser fileChooser, Component parent)
  5. chooseDirectory(Component parentComponent, File directory, String title)
  6. chooseDirectory(String name, final String desc, File curdir)