Java JFileChooser saveFile(Component parent, File defaultFile)

Here you can find the source of saveFile(Component parent, File defaultFile)

Description

Open save file dialog and return the selected fie.

License

Open Source License

Parameter

Parameter Description
parent The parent of the dialog.
defaultFile Default file.

Return

The selected file if comfirmed by user, null otherwise.

Declaration

public static File saveFile(Component parent, File defaultFile) 

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 {
    /**/*  ww w  .j  ava  2s.  co m*/
     * Open save file dialog and return the selected fie.
     * 
     * @param parent
     *            The parent of the dialog.
     * @param defaultFile
     *            Default file.
     * @return The selected file if comfirmed by user, null otherwise.
     */
    public static File saveFile(Component parent, File defaultFile) {
        JFileChooser chooser = new JFileChooser();
        if (defaultFile != null) {
            chooser.setSelectedFile(defaultFile);
        }

        if (chooser.showSaveDialog(parent) == JFileChooser.APPROVE_OPTION) {
            return chooser.getSelectedFile();
        }
        return null;
    }
}

Related

  1. readFromFile()
  2. removeChoosableFileFilters(JFileChooser fc)
  3. retrieveFilesFromDir(File basedir, FileFilter filter)
  4. run_file_chooser(String file_desc, String extension)
  5. save(JFileChooser fileChooser, Runnable action)
  6. saveFile(String title, File currentDir, javax.swing.filechooser.FileFilter filter)
  7. saveObject(final Object content, final String description, final String extension, final File file)
  8. saveSystemFiles(Component owner)
  9. saveToFile(Object obj)