JDK-6612740 : Nimbus L&F: Can't get icon with UIManager.getIcon("FileView.directoryIcon");
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 6u5
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2007-10-03
  • Updated: 2013-11-04
  • Resolved: 2007-12-07
Related Reports
Duplicate :  
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.6.0_05-ea"
Java(TM) SE Runtime Environment (build 1.6.0_05-ea-b04)
Java HotSpot(TM) Client VM (build 1.6.0_05-ea-b04, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]

A DESCRIPTION OF THE PROBLEM :
Most other look and feels allow the developer to get the icon used to represent a directory or folder by using the code:

Icon folderIcon = UIManager.getIcon("FileView.directoryIcon");

This works on Metal, and the system look and feels on Windows, Mac, and Linux.

It does not work with Nimbus.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Set the look and feel to Nimbus and render a button with the icon value set to that returned from:
 UIManager.getIcon("FileView.directoryIcon")

e.g.
JButton browseButton = new JButton(UIManager.getIcon("FileView.directoryIcon"));


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The icon used for folders should be returned.
ACTUAL -
return value of null

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
package nimbusbug;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;

public class Main {

    public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				iconTest();
			}
		});
    }

	public static void iconTest() {
		boolean showBug = true; // change to see the results with System L&F
		try {
			UIManager.setLookAndFeel(
					showBug
					? "sun.swing.plaf.nimbus.NimbusLookAndFeel"
					: UIManager.getSystemLookAndFeelClassName());
		} catch (Exception e) {
			e.printStackTrace();
		}
        JFrame frame = new JFrame("Nimbus Issues");
		JButton browseButton = new JButton(UIManager.getIcon("FileView.directoryIcon"));
		JPanel p = new JPanel();
		p.add(new JLabel("This would make a greate 'browse' button:"));
		p.add(browseButton);
		frame.setContentPane(p);
		frame.pack();
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setVisible(true);
	}
}

---------- END SOURCE ----------

Comments
EVALUATION There are a many keys that are available in LAFs like Metal and Windows that are not in spec but are commonly used by app developers. We are adding the main set in bug 6612359 including the FileView icons.
07-12-2007

EVALUATION Agreed. We are not bound to support all UI keys in other LAFs, but this is an easy one to support, so as Alex says, why not? There are really 5 keys that should be supported here: FileView.directoryIcon FileView.fileIcon FileView.computerIcon FileView.hardDriveIcon FileView.floppyDriveIcon These icons are already in UIDefaults under these keys: FileChooser.directoryIcon FileChooser.fileIcon FileChooser.hardDriveIcon FileChooser.floppyDriveIcon But there is no computerIcon. Not sure what it represents, and whether "FileChooser.homeFolderIcon" is the right thing.
16-10-2007

EVALUATION We don't specify UI properties so actually we don't have to support it for Nimbus but if it is easy to support FileView.directoryIcon for Nimbus, why not ? assigned to Nimbus team
04-10-2007