开发者

Enforce file filters in JFileChooser

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 th开发者_如何学Ce user has selected the file, but this may cause overwriting an existing file.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜