Here you can find the source of selectNonExistingFile(Component parent, String extensionWanted)
public static String selectNonExistingFile(Component parent, String extensionWanted)
//package com.java2s; //License from project: Open Source License import java.awt.Component; import java.io.*; import javax.swing.JFileChooser; import javax.swing.filechooser.FileFilter; public class Main { private static File lastChooserPath; public static String selectNonExistingFile(Component parent, String extensionWanted) { String forReturn = null;/*from ww w. jav a 2s.co m*/ final String endWith = extensionWanted; JFileChooser chooser = new JFileChooser(lastChooserPath); chooser.setFileFilter(new FileFilter() { @Override public boolean accept(File file) { String filename = file.getName(); return (filename.endsWith(endWith) || file.isDirectory()); } @Override public String getDescription() { return endWith; } }); int result = chooser.showSaveDialog(parent); if (result == JFileChooser.APPROVE_OPTION) { try { lastChooserPath = chooser.getCurrentDirectory(); forReturn = chooser.getSelectedFile().getCanonicalPath(); } catch (Exception e) { e.printStackTrace(); } } if (forReturn != null) { if (!forReturn.endsWith(extensionWanted)) { forReturn += extensionWanted; } } return forReturn; } }