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

Here you can find the source of allPlatformGetFile(String dialogTitle, File locationIn, final String fileExtension, FileFilter nonMacFileFilter, boolean allowMultipleSelect, JFrame 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,
        JFrame parentFrame) 

Method Source Code

//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;
    }
}

Related

  1. addEscapeListener(final JFrame frame)
  2. addJFrameReporter(JFrame to)
  3. addPanelToFrame(final JFrame frame, final JPanel panel, final String title)
  4. addProgressBar(final JFrame win)
  5. addToQue(JFrame frame)
  6. askSave(JFrame frame)
  7. attachAccelerator(Action action, JFrame frame)
  8. btnMnemonicAndToolTip(JFrame frame, JButton a, JButton b, JButton c, JButton e, JButton h, JButton i, JButton l, JButton m, JButton o, JButton p, JButton s, JButton t, JButton enter, JButton altEnter)
  9. buildButton(String btnName, JFrame frame, int x, int y, int w, int h)