Search code examples
javaswingjfilechoosernimbusuidefaults

UIManager color at a JFileChooser


I'm using Nimbus Look and Feel, with only 3 changes at its colors:

UIManager.put("nimbusSelection", new Color(164,164,164));
UIManager.put("nimbusSelectionBackground", new Color(214,217,223));
UIManager.put("nimbusSelectedText", Color.BLACK);

My FileChooser looks like this:

enter image description here

So selected file's name appears in white and looks bad, and it also happens for the file type selected at the combobox. I want to change it to Black, but nimbusSelectedText is already black and is not working.

I also had a look at the Nimbus Defaults guide at http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/_nimbusDefaults.html#primary and i see no parameter at FileChooser or Combobox to fix this.

Any help identifying the necessary parameters? Thanks


Solution

  • Well, there is one way possible to do it. You can get the JList from your JFileChooser and modify it:

    public boolean getJList(Container c)
    {
        Component[] cmps = c.getComponents();
        for (Component cmp : cmps)
        {
            if (cmp instanceof JList)
            {
                modifyJList((JList)cmp);
                return true;
            }
            if (cmp instanceof Container)
            {
                if(getJList((Container) cmp)) return true;
            }
        }
        return false;
    }
    private void modifyJList(JList list)
    {
        // Here you can modify your JList
    }
    

    and to use it, just call getJList():

    JFileChooser chooser = new JFileChooser();
    getJList(chooser);