JDK-4883120 : Win L&F: Bug 4174290 not fixed. Disabled JTextField background should be grey
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.4.1,1.4.2
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_nt,windows_2000
  • CPU: x86
  • Submitted: 2003-06-24
  • Updated: 2003-08-15
  • Resolved: 2003-08-15
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
5.0 tigerFixed
Related Reports
Duplicate :  
Relates :  
Relates :  
Relates :  
Relates :  
Description

Name: pa48320			Date: 06/24/2003

Text field backgrounds should be coloured gray when fields are disabled. Currently the text itself is grayed out, but the background remains white. Often times, however, there is no text in the field so the user has no indication that the field is disabled.

If you disable a Swing JTextField so that it is disabled and hence non-editable, it retains the same background colour as the editable version. This is not the way Swing's Windows L&F should behave.

Under the Windows XP L&F 1.4.2 with "adjust for best appearance" set, the disabled field looks correct, but non-XP L&F retain this very confusing behaviour.

To simulate the problem implement the following code:

*****************************************************
package pfstest;

import javax.swing.*;
import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.UIManager;

public class GuiBug extends JFrame {

    JTextField enabled_and_editable;
    JTextField disabled;
    JTextField disabled_and_uneditable;
    JTextField uneditable;

    public static void main(String[] args) {
 	try {
  UIManager.setLookAndFeel"com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
	    //
            UIManager.setLookAndFeel
                ("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
	    //
            UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
 	} catch (Throwable t) {
		t.printStackTrace();
 	}
        GuiBug text = new GuiBug();
 		text.show();
	}

	public GuiBug() {

 		enabled_and_editable = new JTextField("Enabled and Editable");
		disabled = new JTextField("Disabled");
		disabled_and_uneditable =
                       new JTextField("Disabled and uneditable");
 		uneditable = new JTextField("Uneditable");
 		disabled.setEnabled(false);
 		uneditable.setEditable(false);
 		disabled_and_uneditable.setEnabled(false);
 		disabled_and_uneditable.setEditable(false);

 		Box b = new Box(BoxLayout.Y_AXIS);
 		b.add(enabled_and_editable);
 		b.add(Box.createVerticalStrut(10));
 		b.add(disabled);
 		b.add(Box.createVerticalStrut(10));
 		b.add(uneditable);
 		b.add(Box.createVerticalStrut(10));
 		b.add(disabled_and_uneditable);
 		b.add(Box.createVerticalStrut(10));

 		getContentPane().add("Center", b);
 		pack();
 	}

}
*****************************************************

Thus if one has an editable JTextField and one disables it (as a consequence of which it becomes non-editable) the background color should be different from an editable JTextField.  So a UI would just need to disable a JTextField if it was in a group of components which was disabled (say they were grouped as one of several choices
chosen using radio buttons).  In other words there would be
no need for a well-behaved UI  to set it non-editable AND
disable it for it to get the appropriate L&F under Windows.

The 1.4.2. behavior seems to strenghthen the case that the look and feel (non-xp) is wrong?   Obviously, under the XP look and feel the
feeling is that "disabled" should display the same way as "disabled and uneditable", but they don't seem to be adhering to the same behaviour with non-XP look and feel - inconsistency?  Shouldn't the equivalent Windows control when disabled have a background similar to the "disabled and uneditable"?




Under 1.4.2, I noticed no difference.  Here's the sample program output:



Then I realized that I'd set my computer to "adjust for best performance".  When
I change it to "adjust for best appearance" and rerun the program I see (which
is what my user was complaining that I should be doing and which started this
thread):



I guess I don't quite understand how the look and feel interacts with the OS's
appearance / performance selection that I make.


======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: tiger FIXED IN: tiger INTEGRATED IN: tiger tiger-b16
14-06-2004

WORK AROUND Name: pa48320 Date: 06/24/2003 None ====================================================================== Override the method setEditable() and force the background color. Create new Color objects to make sure they don't implement UIResource. class MyTextField extends JTextField { private Color editableColor = new Color(UIManager.getColor("TextField.background").getRGB()); private Color readonlyColor = new Color(UIManager.getColor("TextField.inactiveBackground").getRGB()); MyTextField(String text) { super(text); } public void setEditable(boolean b) { super.setEditable(b); setBackground(b ? editableColor : readonlyColor); } } ###@###.### 2003-06-24
24-06-2003

EVALUATION This is a duplicate of bug 4174290, which was marked as integrated in 1.4. It takes care of the disabled state, but not readonly. That bug can't be reopened, so this bug will be used instead. Will fix for next release. ###@###.### 2003-06-24 Correction. The readonly state was fixed earlier, but not the disabled state. ###@###.### 2003-07-25 Fixed for Windows L&F only. ###@###.### 2003-08-08
24-06-2003