JFileChooser.showSaveDialog(...) - 如何设置建议的文件名 [英] JFileChooser.showSaveDialog(...) - how to set suggested file name

查看:184
本文介绍了JFileChooser.showSaveDialog(...) - 如何设置建议的文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JFileChooser 似乎缺少一种特征:一种在保存文件时建议文件名的方法(通常被选中的东西,以便在用户被替换时开始输入)。

The JFileChooser seems to be missing afeature: a way to suggest the file name when saving a file (the thing that usually gets selected so that it would get replaced when user starts typing).

有没有解决方法?

推荐答案

如果我理解正确,您需要使用 setSelectedFile 方法。

If I understand you correctly, you need to use the setSelectedFile method.

JFileChooser jFileChooser = new JFileChooser();
jFileChooser.setSelectedFile(new File("fileToSave.txt"));
jFileChooser.showSaveDialog(parent);

该文件不需要存在。

编辑:如果您使用绝对路径传递文件, JFileChooser 将尝试将自己定位在该目录中(如果存在)。

If you pass a File with an absolute path, JFileChooser will try to position itself in that directory (if it exists).

这篇关于JFileChooser.showSaveDialog(...) - 如何设置建议的文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆