Here you can find the source of allPlatformGetFile(String dialogTitle, File locationIn, final String fileExtension, FileFilter nonMacFileFilter, boolean allowMultipleSelect, JFrame parentFrame)
Parameter | Description |
---|---|
dialogTitle | a parameter |
locationIn | a parameter |
fileExtension | a parameter |
nonMacFileFilter | a parameter |
allowMultipleSelect | a parameter |
parentFrame | a parameter |
public synchronized static File[] allPlatformGetFile(String dialogTitle, File locationIn, final String fileExtension, FileFilter nonMacFileFilter, boolean allowMultipleSelect, JFrame parentFrame)
//package com.java2s; /*/*from www . jav a 2 s . co m*/ * FileHelper.java * * Created on December 15, 2007, 10:23 AM * * * Copyright 2006-2015 James F. Bowring and www.Earth-Time.org * * 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.JFrame; import javax.swing.filechooser.FileFilter; public class Main { /** * * @param dialogTitle * @param locationIn * @param fileExtension * @param nonMacFileFilter * @param allowMultipleSelect * @param parentFrame * @return */ public synchronized static File[] allPlatformGetFile(String dialogTitle, File locationIn, final String fileExtension, FileFilter nonMacFileFilter, boolean allowMultipleSelect, JFrame parentFrame) { // Nov 2008 note: http://developer.apple.com/samplecode/FunWithFileDialogs/listing3.html File location = locationIn; if (location == null) { location = new File("default location"); } File[] returnFile = new File[] { null }; // nov 2008 went to swing only JFileChooser fc = new JFileChooser(location); fc.setDialogType(JFileChooser.OPEN_DIALOG); fc.addChoosableFileFilter(nonMacFileFilter); fc.setDialogTitle(dialogTitle); fc.setMultiSelectionEnabled(allowMultipleSelect); fc.setAcceptAllFileFilterUsed(true); fc.setFileFilter(nonMacFileFilter); // Show open dialog; this method does not return until the dialog is closed // System.out.println("made it here"); int result; result = fc.showOpenDialog(parentFrame); // System.out.println("AND made it here"); if (result == JFileChooser.APPROVE_OPTION) { if (allowMultipleSelect) { returnFile = fc.getSelectedFiles(); } else { returnFile = new File[] { fc.getSelectedFile() }; } } return returnFile; } }