0

这是我上一个问题的后续问题:

在 Java 中需要带有文件类型过滤器的 FileDialog

我有一个 JFileChooser(使用它而不是 FileDialog,所以我可以有一个文件类型过滤器)并且我已经设法为我们的较暗配色方案选项设置了相当不错的样式,除了左侧的那个小面板。我终于发现上面的那个是“ToolBar.background”,但我不知道那个叫什么。

帮助?

替代文字 http://img151.imageshack.us/img151/6816/filedialog.jpg

4

2 回答 2

0

我不知道如何改变它的颜色,但我知道如何摆脱它:

UIManager.put("FileChooser.noPlacesBar", Boolean.TRUE);

或者,如果您真的希望显示面板,那么您可以搜索源代码以查看该面板是如何创建的,以查看是否可以覆盖其默认颜色。

于 2009-08-11T02:12:43.763 回答
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 中的第一个组件。我打算再把它打开一两天,以防其他人可以向我展示更“优雅”的东西。

于 2009-08-12T15:10:55.453 回答