这是我上一篇的后续问题:
Need FileDialog with a file type filter in Java
我有一个JFileChooser(使用它而不是FileDialog,所以我可以有一个文件类型过滤器)我已经设法为我们的深色配色选项相当不错,除了左边的那个小面板。我终于发现顶部的那个是“ToolBar.background”,但我不知道那个叫什么。
帮助?
alt text http://img151.imageshack.us/img151/6816/filedialog.jpg
答案 0 :(得分:0)
我不知道如何改变它的颜色,但我知道如何摆脱它:
UIManager.put("FileChooser.noPlacesBar", Boolean.TRUE);
或者,如果您真的想要显示面板,那么您可能会搜索源代码以查看该面板是如何创建的,以查看是否可以覆盖其默认颜色。
答案 1 :(得分:0)
我最终通过查看WindowsPlacesBar的源代码找出了该属性的名称:
Color bgColor = new Color(UIManager.getColor("ToolBar.shadow").getRGB());
setBackground(bgColor);
我设置了ToolBar.shadow但没有改变。进一步探索最终帮助我意识到XPStyle.subAppName属性覆盖了我放入的任何内容。我添加了这段代码:
JFileChooser chooser = new JFileChooser();
setWindowsPlacesBackground( chooser );
private void setWindowsPlacesBackground( Container con ) {
Component[] jc = con.getComponents();
for( int i = 0; i < jc.length; i++ ) {
Component c = jc[i];
if( c instanceof WindowsPlacesBar ) {
((WindowsPlacesBar) c).putClientProperty("XPStyle.subAppName", null);
return;
}
if( c instanceof Container ) {
setWindowsPlacesBackground( (Container)c );
}
}
}
通过取消该属性,它允许我的颜色和方案通过。我仍然觉得应该有一个更简洁的方法来解决它,而不是迭代容器,但我找不到它。看起来WindowsPlacesBar似乎总是FileChooser中的第一个组件。我打算将这个开放一两天,以防万一其他人能给我看一些更“优雅”的东西。