Java JFrame Parent AllPlatformGetFile(String dialogTitle, File locationIn, final String fileExtension, FileFilter nonMacFileFilter, boolean allowMultipleSelect, JLayeredPane parentFrame)

Here you can find the source of AllPlatformGetFile(String dialogTitle, File locationIn, final String fileExtension, FileFilter nonMacFileFilter, boolean allowMultipleSelect, JLayeredPane parentFrame)

Description

All Platform Get File

License

Apache License

Parameter

Parameter Description
dialogTitle a parameter
locationIn a parameter
fileExtension a parameter
nonMacFileFilter a parameter
allowMultipleSelect a parameter
parentFrame a parameter

Declaration

public synchronized static File[] AllPlatformGetFile(String dialogTitle, File locationIn,
        final String fileExtension, FileFilter nonMacFileFilter, boolean allowMultipleSelect,
        JLayeredPane parentFrame) 

Method Source Code

//package com.java2s;
/*/*  w ww  .j a  v  a  2 s  .c  om*/
 * Copyright 2006-2016 CIRDLES.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.JLayeredPane;

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,
            JLayeredPane 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
        int result;
        result = fc.showOpenDialog(parentFrame);

        if (result == JFileChooser.APPROVE_OPTION) {
            if (allowMultipleSelect) {
                returnFile = fc.getSelectedFiles();
            } else {
                returnFile = new File[] { fc.getSelectedFile() };
            }
        }

        return returnFile;
    }
}

Related

  1. AllPlatformSaveAs(Frame parentFrame, String dialogTitle, String directory, final String fileExtension, String fractionFileName, FileFilter nonMacFileFilter)
  2. AllPlatformSaveAs(Frame parentFrame, String dialogTitle, String directory, final String fileExtension, String fractionFileName, FileFilter nonMacFileFilter)
  3. buildParentFrame(Object inp)
  4. centreOverFrame(JInternalFrame win, JInternalFrame parent)