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

Regression: RadioButton custom colours not behaving as expected

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P3 P3
    • 6u26
    • 6u26
    • client-libs

      REGRESSION
      ----------
      Appearance changed in JDK 6 (same in JDK 7).
        
      SYNOPSIS
      --------
      Regression: RadioButton custom colours not behaving as expected

      JDK VERSION
      -----------
      Java 6 (tested with 6u26)
      JDK 7 (tested with b147)
      Not reproducible with 5.0

      DESCRIPTION
      -----------
      When creating a custom look and feel for radio buttons, the RadioButton.foreground key/value seems to override the RadioButtonMenuItem.disabledForeground key/value. For example, if we set RadioButtonMenuItem.disabledForeground grey, and RadioButton.foreground to black, disabled radio buttons appear black rather than grey. This did not happen with 5.0 - in 5.0 the RadioButtonMenuItem.disabledForeground key/value seems to take precedence.

      REPRODUCTION INSTRUCTIONS
      -------------------------
      Compile and run the attached testcase

      Expected behaviour (seen with 5.0):
         The disabled radio button label ("Button 2") should be grey

      Observed behaviour (seen with Java 6 and JDK 7):
         The disabled radio button label ("Button 2") is black

      TESTCASE
      --------
      import java.awt.*;
      import java.awt.event.*;
      import javax.swing.*;
      import com.sun.java.swing.plaf.windows.WindowsLookAndFeel;

      public class SimplifiedTest {
         public static void main(String args[]) throws Exception {
             JFrame frame = new JFrame();
             frame.setTitle("SimplifiedTest");
             frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         
             UIManager.setLookAndFeel(new MyLookAndFeel());
             
             JRadioButton button1 = new JRadioButton("Button 1");
             JRadioButton button2 = new JRadioButton("Button 2");
             button2.setEnabled(false);

             JPanel mainPanel = new JPanel();
             mainPanel.setLayout(new GridLayout(2,1));
             mainPanel.add(button1);
             mainPanel.add(button2);

             frame.add(mainPanel);
             frame.pack();
             frame.setVisible(true);
         }
      }

      class MyLookAndFeel extends WindowsLookAndFeel {
         protected void initComponentDefaults(UIDefaults table) {
             super.initComponentDefaults(table);

             Object[] defaults = {
                                 "RadioButton.foreground", Color.BLACK, // comment this line out and the problem disappears
                         "RadioButtonMenuItem.foreground", Color.BLACK,
                 "RadioButtonMenuItem.disabledForeground", Color.GRAY,
             };

             table.putDefaults(defaults);
         }
      }

            Unassigned Unassigned
            dkorbel David Korbel (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: