public File chooseOutputFile(String defaultName, String suffixWithoutDot, String dialogTitle) { String defaultPath = this.getFileChooser().getCurrentDirectory().getPath(); if (defaultName != null && defaultName.length() > 0) defaultPath += File.separatorChar + defaultName; if (suffixWithoutDot != null && suffixWithoutDot.length() > 0) defaultPath += "." + suffixWithoutDot; if (dialogTitle == null || dialogTitle.length() == 0) dialogTitle = "Choose Save Location"; this.getFileChooser().setDialogTitle(dialogTitle); this.getFileChooser().setSelectedFile(new File(defaultPath)); this.getFileChooser().setMultiSelectionEnabled(false); while (true) { int status = this.getFileChooser().showSaveDialog(this.getFrame()); if (status != JFileChooser.APPROVE_OPTION) return null; File outFile = this.getFileChooser().getSelectedFile(); if (outFile == null) { this.showMessageDialog("No location selected", "No Selection", JOptionPane.ERROR_MESSAGE); continue; } if (suffixWithoutDot != null && suffixWithoutDot.length() > 0) outFile = Util.ensureFileSuffix(outFile, suffixWithoutDot); if (outFile.exists()) { status = this.showConfirmFileOverwriteDialog(outFile); if (status == JOptionPane.NO_OPTION) continue; if (status == JOptionPane.CANCEL_OPTION) return null; } return outFile; } }