Nimbus JToolBar Bug

I just submitted a workaround for this Nimbus bug: 6780500. I am unable to watch or vote for bugs…the bug tracking tool seems to have a bug.

The problem is, disabled items in JToolBar use a black font and don’t look any different than enabled items.

This example requires Java6u10 or later, and demonstrates the bug:

public class ToolbarBug extends JFrame {
  public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {
      public void run() {
        try {
          UIManager.setLookAndFeel(
               "com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
        } catch (Exception e) {
          throw new RuntimeException(e);
        }
        new ToolbarBug().setVisible(true);
      }
    });
  }

  public ToolbarBug() {
    /*
    // un-comment these lines for the workaround
    UIManager.put("ToolBar:Button[Disabled].textForeground",
            UIManager.getColor("nimbusDisabledText"));
    UIManager.put("ToolBar:ToggleButton[Disabled].textForeground",
            UIManager.getColor("nimbusDisabledText"));
    */

    JToolBar tb = new JToolBar();
    tb.add(new JButton("Enabled"));
    JButton disabled = new JButton("Disabled");
    disabled.setEnabled(false);
    tb.add(disabled);

    add(tb, BorderLayout.NORTH);

    pack();
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  }
}

With the fix, the example looks right:


Comments are closed.