Here you can find the source of chooseFilesForOpen(String title, FileFilter filter, File initialDir)
Parameter | Description |
---|---|
parent | the parent frame (typically the Savant main frame) |
title | title for the dialog |
filter | controls which files to display (null for no filtering) |
initialDir | initial directory for the dialog |
public static File[] chooseFilesForOpen(String title, FileFilter filter, File initialDir)
//package com.java2s; /*/*from w ww.ja v a 2s. co m*/ * Copyright 2010-2012 University of Toronto * * 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 java.io.File; import javax.swing.JFileChooser; import javax.swing.filechooser.FileFilter; public class Main { /** * Open-file dialog variant which lets user select multiple files on Windows and * Linux. * * @param parent the parent frame (typically the Savant main frame) * @param title title for the dialog * @param filter controls which files to display (null for no filtering) * @param initialDir initial directory for the dialog * @return an array of selected files; an empty array if nothing is selected */ public static File[] chooseFilesForOpen(String title, FileFilter filter, File initialDir) { // unfortunately, we need function over aesthetics... /* if (MiscUtils.MAC) { // Mac AWT FileDialog doesn't support multiple selection. File[] files = chooseFilesForOpen( parent, title, filter, initialDir); if (files != null) { return files; } } else { * */ JFileChooser fd = new JFileChooser(); fd.setDialogTitle(title); fd.setSelectedFile(initialDir); fd.setDialogType(JFileChooser.OPEN_DIALOG); if (filter != null) { fd.setFileFilter(filter); } fd.setMultiSelectionEnabled(true); int result = fd.showOpenDialog(null); if (result == JFileChooser.APPROVE_OPTION) { return fd.getSelectedFiles(); } //} return new File[] {}; } }