Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6709439

Disabled menu items with foreground color set are not drawn disabled on Vista

    XMLWordPrintable

    Details

      Description

      FULL PRODUCT VERSION :
      java version "1.6.0_04"
      Java(TM) SE Runtime Environment (build 1.6.0_04-b12)
      Java HotSpot(TM) Client VM (build 10.0-b19, mixed mode, sharing)

      But the bug also exists on

      java version "1.7.0-ea"
      Java(TM) SE Runtime Environment (build 1.7.0-ea-b24)
      Java HotSpot(TM) Client VM (build 12.0-b01, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.0.6001] (Vista)

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      Must be using the Vista Look and Feel

      A DESCRIPTION OF THE PROBLEM :
      Using Vista, when you set the foreground color of a menu item, and then disable it, the text of menu item is still rendered with the foreground color rather than appearing disabled.

      This is inconsistent with menu item rendering on all other platforms (Win classic L&F, Win XP L&F, Ocean, etc.). In those cases, the text of disabled menu items looks uniformly disabled regardless of foreground color.

      There is a similar disabled-appearance bug regarding buttons, http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6574390 (that issue occurs on XP as well).

      Our customers rely on this disabled-appearance behavior.

      This is new since the implementation of http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6432667 which brought the introduction of Vista-looking menus.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the program below on Windows Vista with the Vista theme set.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Expected the menu items to appear disabled, as they do on WinXP, Classic, etc.
      ACTUAL -
      The menu items are still drawn in red.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.*;
      import java.awt.event.*;
      import javax.swing.*;
      import javax.swing.event.*;

      public class VistaMenuTest
      {
          public static void main(final String[] args)
              throws Exception
          {
              UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

              JMenu fileMenu = new JMenu("File");

              JMenuItem item1 = new JMenuItem("Menu Item");
              item1.setForeground(Color.RED);
              item1.setEnabled(false);
              fileMenu.add(item1);

              JRadioButtonMenuItem item2 = new JRadioButtonMenuItem("Radio");
              item2.setForeground(Color.RED);
              item2.setEnabled(false);
              fileMenu.add(item2);

              JCheckBoxMenuItem item3 = new JCheckBoxMenuItem("Check");
              item3.setForeground(Color.RED);
              item3.setEnabled(false);
              fileMenu.add(item3);

              JMenu item4 = new JMenu("Menu");
              item4.setForeground(Color.RED);
              item4.setEnabled(false);
              fileMenu.add(item4);
              
              JMenuBar menubar = new JMenuBar();
              menubar.add(fileMenu);
              
              JFrame frame = new JFrame("Menu Test");
              frame.setJMenuBar(menubar);
              frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
              frame.setSize(300, 200);
              frame.setLocationRelativeTo(null);
              frame.setVisible(true);
          }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      Override getForeground() in JMenuItem, etc., subclasses:

          @Override
          public Color getForeground()
          {
              return isVistaLookAndFeel() && !isEnabled()
                      ? UIManager.getColor("MenuItem.foreground")
                      : super.getForeground();
          }

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: