Here you can find the source of chooseFiles(String title, File currentDir)
Parameter | Description |
---|---|
title | The title of the file-chooser window. |
currentDir | The root directory. If null, new File(".") will be used. |
public static File[] chooseFiles(String title, File currentDir)
//package com.java2s; /*/*from ww w. j a v a 2 s . c o m*/ * Copyright 2014 Aritz Lopez * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import javax.swing.JFileChooser; import java.io.File; public class Main { /** * Open a {@link javax.swing.JFileChooser} with multi-selection enabled, and return the selected file(s), or null if closed or cancelled. * * @param title The title of the file-chooser window. * @param currentDir The root directory. If null, {@code new File(".")} will be used. * @return The chosen file(s), or null if none was chosen. */ public static File[] chooseFiles(String title, File currentDir) { if (currentDir == null) currentDir = new File("."); JFileChooser fileChooser = new JFileChooser(); fileChooser.setCurrentDirectory(currentDir); fileChooser.setDialogTitle(title); fileChooser.setMultiSelectionEnabled(true); int result = fileChooser.showOpenDialog(null); if (result == JFileChooser.APPROVE_OPTION) { return fileChooser.getSelectedFiles(); } return null; } }