Here you can find the source of chooseFile(Component parent, String title, boolean open)
public static File chooseFile(Component parent, String title, boolean open)
//package com.java2s; /*//from w w w . ja v a2 s . co m * ArikTools * Copyright (C) Arik Z.Lakritz, Peter Macko, and David K. Wittenberg * * This file is part of ArikTools. * * ArikTools is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * ArikTools is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with ArikTools. If not, see <http://www.gnu.org/licenses/>. */ import java.awt.*; import java.io.*; import javax.swing.*; public class Main { /** * Chooses a file to open or save */ public static File chooseFile(Component parent, String title, boolean open) { 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); } if (r != JFileChooser.APPROVE_OPTION) return null; return fc.getSelectedFile(); } }