Change color of WindowsPlacesBar in JFileChooser

拜拜、爱过 提交于 2019-12-12 01:17:08

问题


This is a followup question to my previous one:

Need FileDialog with a file type filter in Java

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.

Help?

alt text http://img151.imageshack.us/img151/6816/filedialog.jpg


回答1:


I have no idea how to change its color, but I do know how to get rid of it:

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

Or, if you really want the panel displayed then maybe you search the source code to see how that panel is created to see if any override of its default color is possible.




回答2:


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);

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 );
    }
  }
}

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."



来源:https://stackoverflow.com/questions/1257474/change-color-of-windowsplacesbar-in-jfilechooser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!