在JFileChooser中更改WindowsPlacesBar的颜色 [英] Change color of WindowsPlacesBar in JFileChooser

查看:78
本文介绍了在JFileChooser中更改WindowsPlacesBar的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

This is a followup question to my previous one:

需要FileDialog和Java中的文件类型过滤器

我有一个JFileChooser(使用它而不是FileDialog,所以我可以有一个文件类型过滤器),而且我设法为我们较深的配色方案设置了相当不错的样式,除了左边的那个小面板.我终于弄清楚了最上面的那个是"ToolBar.background",但是我不知道那个叫什么.

I've got a JFileChooser (using that instead of a FileDialog so I can have a file type filter) and I've managed to style it pretty decently for our darker color scheme option except for that little panel on the left. I FINALLY figured out that the one on top was the "ToolBar.background" but I have no idea what that one is called.

帮助?

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

推荐答案

我最终通过查看WindowsPlacesBar的源代码来弄清楚该属性的名称:

I eventually figured out that the name of the property by looking in the source code for the WindowsPlacesBar:

Color bgColor = new Color(UIManager.getColor("ToolBar.shadow").getRGB());
setBackground(bgColor);

尽管我设置了ToolBar.shadow,但没有任何改变.进一步摸索最终使我意识到XPStyle.subAppName属性将覆盖我放入的所有内容.我添加了以下代码:

I set the ToolBar.shadow though and nothing changed. Further poking around eventually helped me to realize that the XPStyle.subAppName property was overriding anything I put in. I added this piece of code:

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中的第一个组件.我打算再开放一两天,以防其他人向我展示一些优雅"的东西.

By unsetting that property, it allowed my colors and schemes to come through. I still feel like there should be a more clean way of unsetting it than iterating through the containers, but I couldn't find it. It did seem like the WindowsPlacesBar was always the first component in the FileChooser. I'm going to leave this open for another day or two just in case somebody else can show me something more "elegant."

这篇关于在JFileChooser中更改WindowsPlacesBar的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆