JDK-5037097 : JTextField does not show proper background color when disabled (Windows LAF)
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.4.2
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2004-04-23
  • Updated: 2004-04-23
  • Resolved: 2004-04-23
Related Reports
Duplicate :  
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) 
======================================================================

Comments
EVALUATION Duplicate of 4883120, which is fixed in tiger. ###@###.### 2004-04-23
23-04-2004