Question

How can I enforce the JFileChooser filetype (when saving). I have implemented a file filter (CSV filetype) but it does not in any way enforce the file extension on the user.

I need the file chooser to append the file extension to the filename if the user has not done so. I am guessing that it would be possible to check fileChooser.getSelectedFile() for the file extension after the user has selected the file, but this may cause overwriting an existing file.

Was it helpful?

Solution

Your suggestion of appending the extension to the result of calling getSelectedFile() is how I would approach this, prompting the user with a confirmation dialog if the action would result in an existing file being overwritten. I have seen many applications take this approach so would say it's fairly intuitive to the user.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top