How to set a default file name to Swing JFileChooser?

风格不统一 提交于 2019-11-30 20:44:10

Use the following code:

        JFileChooser fileChooser = new JFileChooser();
        File file = new File("C:/untitled.txt");
        fileChooser.setCurrentDirectory(file);

You have to specify the complete path to untitled.txt

You have to use the setSelectedFile method and pass a file as a parameter. The file doens't have to exist.
If the path to the file is specified the file chooser will try to point to the file directory if it exists

JFileChooser fileChooser = new JFileChooser(); fileChooser.setSelectedFile(new File("C:\\file.txt")); fileChooser.showSaveDialog(null);

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!