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

JTextField does not show proper background color when disabled (Windows LAF)

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Duplicate
    • Affects Version/s: 1.4.2
    • Fix Version/s: None
    • Component/s: client-libs
    • Labels:

      Description



      Name: gm110360 Date: 04/23/2004


      FULL PRODUCT VERSION :
      java version "1.4.2_01"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_01-b06)
      Java HotSpot(TM) Client VM (build 1.4.2_01-b06, mixed mode)

      FULL OS VERSION :
      Microsoft Windows 2000 [Version 5.00.2195]

      A DESCRIPTION OF THE PROBLEM :
      JTextfield does not draw the proper background color to visually indicate when it is disabled via setEnabled(false) when using the Windows look and feel (haven't checked others).

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the code below

      import javax.swing.*;

      public class Test {
          public static void main(String[] args) {
              JFrame jf = new JFrame();
              JTextField myField = new JTextField(10);
      //below run code fixes the bug
      //JTextFieldFixed myField = new JTextFieldFixed(10);
              myField.setEnabled(false);
              jf.getContentPane().add(myField);
              jf.pack();
              jf.show();
          }
      }

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      myField should have the same disabled background color as other components.
      ACTUAL -
      myField instead has a white background that look the same as an enabled field.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      CUSTOMER SUBMITTED WORKAROUND :
      It's easy enough to extend JTextfield to fix this -- but should I have to?

      import javax.swing.*;

      public class JTextFieldFixed extends JTextField {

        public JTextFieldFixed(int value) {
          super(value);
        }

        public void setEnabled(boolean b) {
          super.setEnabled(b);
          if (b) {
            this.setBackground(UIManager.getColor("TextField.background"));
          }
          else {
            this.setBackground(UIManager.getColor("TextField.inactiveBackground"));
          }
        }
      }
      (Incident Review ID: 214544)
      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              shickeysunw Shannon Hickey (Inactive)
              Reporter:
              gmanwanisunw Girish Manwani (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: