JFileChooser Save Dialog Suggest File Name

user1081326 picture user1081326 · Dec 22, 2012 · Viewed 7.6k times · Source

Possible Duplicate:
JFileChooser.showSaveDialog(…) - how to set suggested file name

I have seen this question asked a few times but no answer has been any help to me. I want the save dialog to suggest a file name like "myFile.txt" using JFileChooser.

Heres what i have:

JFileChooser jFileChooser = new JFileChooser();
jFileChooser.setCurrentDirectory(new File("C:\\"));
jFileChooser.showSaveDialog(null);

Answer

xoned picture xoned · Dec 22, 2012

This will do it:

jFileChooser.setSelectedFile(new File(optionalPath + "myFile.txt"));