3

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);
Community
  • 1
  • 1
user1081326
  • 415
  • 5
  • 10
  • 19
  • 2
    And this does not work? http://stackoverflow.com/questions/356671/jfilechooser-showsavedialog-how-to-set-suggested-file-name – sorencito Dec 22 '12 at 12:42
  • Apologies, never came across those somehow. I even went through the suggestions while typing this. – user1081326 Dec 22 '12 at 12:51

1 Answers1

10

This will do it:

jFileChooser.setSelectedFile(new File(optionalPath + "myFile.txt"));
xoned
  • 2,701
  • 2
  • 31
  • 43