I am working on a program that loads and saves data from text files, and I am asking the user a file name with JFileChooser on load and save.
This question is about
As AvrDragon said, closing with X is not handled. I added a default case to handle all unrelevant options:
final JFileChooser fc = new JFileChooser() {
private static final long serialVersionUID = 7919427933588163126L;
public void approveSelection() {
File f = getSelectedFile();
if (f.exists() && getDialogType() == SAVE_DIALOG) {
int result = JOptionPane.showConfirmDialog(this,
"The file exists, overwrite?", "Existing file",
JOptionPane.YES_NO_CANCEL_OPTION);
switch (result) {
case JOptionPane.YES_OPTION:
super.approveSelection();
return;
case JOptionPane.CANCEL_OPTION:
cancelSelection();
return;
default:
return;
}
}
super.approveSelection();
}
};