Java JFileChooser chooseFile(Component parentComponent, String title, File curDir, String suffix)

Here you can find the source of chooseFile(Component parentComponent, String title, File curDir, String suffix)

Description

choose File

License

Apache License

Declaration

public static File chooseFile(Component parentComponent, String title, File curDir, String suffix) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.awt.Component;

import java.io.File;

import javax.swing.JFileChooser;

import javax.swing.filechooser.FileNameExtensionFilter;

public class Main {

    public static File chooseFile(Component parentComponent, String title) {
        JFileChooser jfc = new JFileChooser();
        jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);
        jfc.showDialog(parentComponent, title);
        return jfc.getSelectedFile();
    }/*from  www.  j av a  2 s .co m*/

    public static File chooseFile(Component parentComponent, String title, String suffix) {
        JFileChooser jfc = new JFileChooser();
        jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);
        jfc.setFileFilter(new FileNameExtensionFilter("." + suffix, suffix));
        jfc.showDialog(parentComponent, title);
        return jfc.getSelectedFile();
    }

    public static File chooseFile(Component parentComponent, String title, File curDir, String suffix) {
        JFileChooser jfc = new JFileChooser();
        jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);
        jfc.setFileFilter(new FileNameExtensionFilter("." + suffix, suffix));
        if (curDir != null) {
            jfc.setCurrentDirectory(curDir);
        }
        jfc.showDialog(parentComponent, title);
        return jfc.getSelectedFile();
    }
}

Related

  1. chooseDirectory(String name, final String desc, File curdir)
  2. chooseFile()
  3. chooseFile()
  4. chooseFile(Component p, String message, boolean toOpen, int fileType)
  5. chooseFile(Component parent, String title, boolean open)
  6. chooseFile(File initialFile, boolean load)
  7. chooseFile(final Component parent, final boolean filesOnly, final String title, final File selectedFile, final FileFilter filter)
  8. ChooseFile(final String desc, final String[] allowed_extensions, String suggested_dir)
  9. chooseFile(JFileChooser fc, Component parent)