JFileChooser.showSaveDialog:所有文件均变灰 [英] JFileChooser.showSaveDialog: All files greyed out
问题描述
我正在尝试使用JFileChooser
获取要加载和保存的文件. openFileDialog()
附带的对话框工作正常,但是当我使用saveFileDialog()
方法时,对话框窗口中的所有文件名均变灰.无论是否使用FileFilter
,都会发生这种情况(我的示例包括一个更好地显示我所看到的内容的示例).
I'm trying to use the JFileChooser
to get files for loading and saving. The dialog that comes up with openFileDialog()
works fine, but when I use the saveFileDialog()
method, the dialog window has all the file names greyed out. This happens with or without a FileFilter
(my example includes one to better show what I'm seeing).
这是一个最小的程序来说明:
Here's a minimal program to illustrate:
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.filechooser.FileNameExtensionFilter;
public class Temp extends JFrame {
public static void main(String[] args){
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JFileChooser chooser = new JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter("Text File", "txt");
chooser.setFileFilter(filter);
frame.setVisible(true);
chooser.showOpenDialog(null);
chooser.showSaveDialog(null);
}
}
这是我在打开"对话框中看到的内容: 打开对话框
Here's what I see in the Open dialog: Open Dialog
这是我在保存"对话框中看到的内容: 保存对话框
Here's what I see in the Save dialog: Save Dialog
尽管显示为灰色,但保存对话框中的所有文件都是可选择的.
Despite being greyed out, all the files in the save dialog are selectable.
如果重要的话,我使用的是Mac/Mountain Lion和Java 7.
I'm on Mac/Mountain Lion and Java 7 if it matters.
这是预期的行为吗?有办法改变吗?
Is this expected behavior? Is there a way to change this?
(根据MadProgrammer的评论+下面的垃圾桶,这似乎与其他(本机)Mac应用程序的外观+感觉一致)
( per comments by MadProgrammer + trashgod below, this appears to be consistent with the look + feel of other (native) Mac apps)
推荐答案
我正在寻找在保存对话框中以正常"颜色显示的
.txt
文件.
这由特定于特定外观的FileChooserUI
代表控制.感觉例如在Mac OS X上为AquaFileChooserUI
.您可以使用其他的L& F,(费力地)编写自己的FileChooserUI
,或开发自定义的
That's controlled by the FileChooserUI
delegate specific to a particular Look & Feel, e.g. AquaFileChooserUI
on Mac OS X. You can use a different L&F, (laboriously) write your own FileChooserUI
, or develop a custom File Browser GUI.
这篇关于JFileChooser.showSaveDialog:所有文件均变灰的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!