JFileChooser保存对话框建议文件名

3

可能是重复问题:
JFileChooser.showSaveDialog(…) - 如何设置建议的文件名

我已经看到过这个问题被问了几次,但没有任何答案对我有帮助。我想让保存对话框使用JFileChooser建议一个文件名,比如"myFile.txt"。

这是我的代码:

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

2
这个不起作用吗? https://dev59.com/pXRC5IYBdhLWcg3wROtQ - sorencito
抱歉,不知何故从未遇到过这些。我甚至在输入时浏览了建议。 - user1081326
1个回答

10
这样做就可以了:
jFileChooser.setSelectedFile(new File(optionalPath + "myFile.txt"));

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接