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

Color differs for disabled buttons when text is html formatted

XMLWordPrintable

      FULL PRODUCT VERSION :
      java version "1.7.0_03"
      Java(TM) SE Runtime Environment (build 1.7.0_03-b05)
      Java HotSpot(TM) Client VM (build 22.1-b02, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Windows 7

      A DESCRIPTION OF THE PROBLEM :
      The problem has already been described in bug 4783068.
      But the workarounds (see code) don't work any more.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile and run and click on the "enabled" checkbox.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Text color of disabled components should always look the same, no matter whether the text is html formatted or not.

      ACTUAL -
      Color differs considerably and text is hardly readable when html formatted and component is disabled.

      REPRODUCIBILITY :
      This bug can be reproduced always.

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

      public class HTMLTextColour extends JFrame implements ActionListener {
        JButton bRegular, bHTML;
        JCheckBox check;

        public HTMLTextColour() {
          setSize(250, 110);
          setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
          setLayout(new FlowLayout());
          bRegular= new JButton("Sample text");
          add(bRegular);
          bHTML= new JButton("<html><font color=\"#333333\">HTML text<html>") {
            public void setEnabled(boolean b) {
      super.setEnabled(b);
      // setForeground(b ? UIManager.getColor("Button.foreground") :
      // UIManager.getColor("Button.disabledText"));
      // setForeground(b ? UIManager.getColor("Label.foreground") :
      // UIManager.getColor("Label.disabledForeground"));
      // setForeground(b ? UIManager.getColor("Label.foreground") :
      // UIManager.getColor(new ColorUIResource(153,153,153)));
      setText(b ? "<html><font color=\"#333333\">HTML text<html>" :
      "<html><font color=red>Should be red<html>");
      // repaint();
            }
          };
          add(bHTML);
          check= new JCheckBox("Enabled", true);
          check.addActionListener(this);
          add(check);
          setVisible(true);
        }

        public static void main(String argsv[]) {
          EventQueue.invokeLater(new Runnable() {
            public void run() {
      new HTMLTextColour();
            }
          });
        }


        public void actionPerformed(ActionEvent evt) {
          bRegular.setEnabled(check.isSelected());
          bHTML.setEnabled(check.isSelected());
      DBG.p(bRegular.getForeground());
      DBG.p(bHTML.getForeground());
        }

      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Overriding "setEnabled(boolean b)" used to be a workaround, but isn't any more.

            rupashka Pavel Porvatov (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: