2012-12-22 37 views
2

可能重複:
JFileChooser.showSaveDialog(…) - how to set suggested file nameJFileChooser的保存對話框建議文件名

我已經看到了這個問題問了幾次,但沒有答案一直對我的幫助。我希望保存對話框使用JFileChooser建議一個像「myFile.txt」這樣的文件名。

繼承人我有什麼:

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

這不起作用? http://stackoverflow.com/questions/356671/jfilechooser-showsavedialog-how-to-set-suggested-file-name – sorencito

+0

道歉,從來沒有遇到過這些莫名其妙。我甚至在輸入時仔細閱讀了這些建議。 – user1081326

回答

7

這將做到這一點:

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