Here you can find the source of createChooser(String lastPath, final boolean checkOverrideFile)
public static JFileChooser createChooser(String lastPath, final boolean checkOverrideFile)
//package com.java2s; /**/* w ww . j av a 2 s .co m*/ * ============================================================================================ * Menthor Editor -- Copyright (c) 2015 * * This file is part of Menthor Editor. Menthor Editor is based on TinyUML and as so it is * distributed under the same license terms. * * Menthor Editor 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 2 of the License, or (at your option) any later version. * * Menthor Editor 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 Menthor Editor; * if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, * MA 02110-1301 USA * ============================================================================================ */ import java.io.File; import javax.swing.JFileChooser; import javax.swing.JOptionPane; public class Main { public static JFileChooser createChooser(String lastPath, final boolean checkOverrideFile) { return new JFileChooser(lastPath) { private static final long serialVersionUID = 1L; @Override public void approveSelection() { File f = getSelectedFile(); if (f.exists() && checkOverrideFile) { int result = JOptionPane.showConfirmDialog(this, "\"" + f.getName() + "\" already exists. Do you want to overwrite it?", "Existing file", JOptionPane.YES_NO_CANCEL_OPTION); switch (result) { case JOptionPane.YES_OPTION: super.approveSelection(); return; case JOptionPane.NO_OPTION: return; case JOptionPane.CLOSED_OPTION: return; case JOptionPane.CANCEL_OPTION: cancelSelection(); return; } } super.approveSelection(); } }; } }