Here you can find the source of saveFile(Component parent, File defaultFile)
Parameter | Description |
---|---|
parent | The parent of the dialog. |
defaultFile | Default file. |
public static File saveFile(Component parent, File defaultFile)
//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; } }