javaswinglook-and-feeluimanager

Look and Feel without hard coded values


Right now I set the LaF like this: UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); It works fine and gives the look and feel I want to have. Sadly at some point in my code, I have to set some icons manually, because the automatical setting of those doesn't work properly (sets wrong icon). I currently have:

if (node.getAllowsChildren()) {
    setIcon(UIManager.getIcon("FileView.directoryIcon"));
}else {
    setIcon(UIManager.getIcon("FileView.fileIcon"));
}

but it doesn't use the LaF icons and I have no idea, on how to find the icons that look like the LaF. So my question is, is there an easy way to get lets say the LaF folder icon?


Design I currently get:

enter image description here

And the design I want to have:

enter image description here


Solution

  • Try using the UIDefaults class to get the values:

    UIDefaults defaults = UIManager.getLookAndFeelDefaults();
    Icon icon = (Icon)defaults.get(...);
    

    Check out UIManager Defaults. This Icons change when the LAF is changed.