如何更改JFileChooser对话框的标题

use*_*774 12 java

我使用JFileChooser.showOpenDialog打开对话框.当它出现时,对话框的标题上有"打开".我想将其更改为"添加",因为我的代码是用于添加新文件.有人会告诉我该怎么做.提前致谢.

有我的对话框. 在此输入图像描述

fle*_*eed 10

JFileChooser的showOpenDialog没有为您提供更改对话框标题的选项(请参阅文档).你必须使用更多的代码.文档中的代码示例很接近:

JFileChooser chooser = new JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter(
    "JPG & GIF Images", "jpg", "gif");
chooser.setFileFilter(filter);
chooser.setDialogTitle("Add new file");
int returnVal = chooser.showOpenDialog(parent);
Run Code Online (Sandbox Code Playgroud)


小智 5

可以在过滤器之前自定义对话框。

JFileChooser fc = new JFileChooser();

fc.setDialogTitle("Title");

fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
Run Code Online (Sandbox Code Playgroud)