Java JFileChooser select_file(Component parent, boolean show_save)

Here you can find the source of select_file(Component parent, boolean show_save)

Description

selecfile

License

Open Source License

Declaration

public static File select_file(Component parent, boolean show_save) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.awt.Component;
import java.io.File;
import javax.swing.JFileChooser;

public class Main {
    public static File select_file(Component parent) {
        return select_file(parent, false, null);
    }/*from   ww  w  .j a  va2 s .  c o m*/

    public static File select_file(Component parent, boolean show_save) {
        return select_file(parent, show_save, null);
    }

    public static File select_file(Component parent, boolean show_save, File starting_dir) {
        JFileChooser file_box = new JFileChooser();
        if (starting_dir != null && starting_dir.isDirectory()) {
            file_box.setCurrentDirectory(starting_dir);
        }

        int choice;
        if (show_save)
            choice = file_box.showSaveDialog(parent);
        else
            choice = file_box.showOpenDialog(parent);
        if (choice == JFileChooser.APPROVE_OPTION) {
            return file_box.getSelectedFile();
        }

        return null;
    }
}

Related

  1. saveFile(Component parent, File defaultFile)
  2. saveFile(String title, File currentDir, javax.swing.filechooser.FileFilter filter)
  3. saveObject(final Object content, final String description, final String extension, final File file)
  4. saveSystemFiles(Component owner)
  5. saveToFile(Object obj)
  6. selectAndSaveToFile(String content, Component parent)
  7. selectDirectory(Component component, String name, File pathToUse)
  8. selectedFiles(JFileChooser chooser)
  9. selectFile(boolean exitOnCancel)