Java Utililty Methods JFileChooser

List of utility methods to do JFileChooser

Description

The list of methods to do JFileChooser are organized into topic(s).

Method

FilechooseFile(Component parent, String title, boolean open)
Chooses a file to open or save
JFileChooser fc = new JFileChooser();
fc.setDialogTitle(title);
fc.setDialogType(open ? JFileChooser.OPEN_DIALOG : JFileChooser.SAVE_DIALOG);
int r = 0;
if (open) {
    r = fc.showOpenDialog(parent);
} else {
    r = fc.showSaveDialog(parent);
...
FilechooseFile(Component parentComponent, String title, File curDir, String suffix)
choose File
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();
...
FilechooseFile(File initialFile, boolean load)
choose File
if (isMac()) {
    FileDialog d = new FileDialog((java.awt.Frame) null);
    d.setMode(load ? FileDialog.LOAD : FileDialog.SAVE);
    if (initialFile != null) {
        d.setDirectory(initialFile.getParent());
        d.setFile(initialFile.getName());
    d.show();
...
FilechooseFile(final Component parent, final boolean filesOnly, final String title, final File selectedFile, final FileFilter filter)
choose File
final JFileChooser chooser = new JFileChooser(selectedFile);
chooser.setApproveButtonText("Select");
if (filter != null)
    chooser.setFileFilter(filter);
chooser.setDialogTitle(title);
chooser.setMultiSelectionEnabled(false);
if (filesOnly)
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
...
StringChooseFile(final String desc, final String[] allowed_extensions, String suggested_dir)
Choose File
String basedir = suggested_dir.isEmpty() ? _last_dir : suggested_dir;
JFileChooser chooser = _NewFileChooserInstance(basedir);
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
if (!desc.isEmpty() && allowed_extensions.length > 0)
    chooser.setFileFilter(newFileFilter(desc, allowed_extensions));
int returnVal = chooser.showOpenDialog(null);
if (returnVal == JFileChooser.APPROVE_OPTION) {
    _last_dir = chooser.getSelectedFile().getAbsolutePath();
...
FilechooseFile(JFileChooser fc, Component parent)
choose File
int returnVal = fc.showOpenDialog(parent);
if (returnVal == JFileChooser.APPROVE_OPTION) {
    File file = fc.getSelectedFile();
    return file;
} else
    return null;
FilechooseFile(String title)
choose File
File f = null;
JFileChooser chooser = new JFileChooser();
chooser.setDialogTitle(title);
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
chooser.setCurrentDirectory(new File("."));
int returnVal = chooser.showOpenDialog(null);
if (returnVal == JFileChooser.APPROVE_OPTION)
    return f = chooser.getSelectedFile();
...
String[]chooseFiles()
choose Files
return chooseFiles(".", "Open Files");
SetchooseFiles(final Component parent)
choose Files
return chooseFiles(parent, null, null);
File[]chooseFiles(String title, File currentDir)
Open a javax.swing.JFileChooser with multi-selection enabled, and return the selected file(s), or null if closed or cancelled.
if (currentDir == null)
    currentDir = new File(".");
JFileChooser fileChooser = new JFileChooser();
fileChooser.setCurrentDirectory(currentDir);
fileChooser.setDialogTitle(title);
fileChooser.setMultiSelectionEnabled(true);
int result = fileChooser.showOpenDialog(null);
if (result == JFileChooser.APPROVE_OPTION) {
...