JDK-4174290 : Disabled JTextField background should be control colour in Windows L&F
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.1,1.1.7,1.3.0
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_nt
  • CPU: x86
  • Submitted: 1998-09-16
  • Updated: 2003-06-25
  • Resolved: 2000-03-09
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
1.4.0 betaFixed
Related Reports
Relates :  
Relates :  
Relates :  
Relates :  
Description
If you disable a Swing JTextField so that is is non-editable, it retains
the same background colour as the editable version.
This is not the way Swing's Windows L&F should behave.

Native win32/windows applications use the "Window" colour for the background
of editable textfields, and use the "3D objects" colour for the background
of non-editable textfields.

These terms are the ones used in the Windows dialog for setting the
Appearance of "items". Users can set these desktop properties dynamically.
Click right button on the windows b/g, bring up the "Properties" dialog,
choose the "Appearance" tab, and Select from the "Item" combox box.
Certain of the items in there allow you to define colour from a palette.
There you can set the "3D objects" and "Window" colours.

For a good example of the way windows native textfields behave,
start Internet Explorer 3.0 or 4.0.
Now select Edit->Options from the menu bar which brings up a dialog box
Select the "Connection" tab.
Ensure that "connect though a proxy server" is checked/enabled.
on IE 4.0 you now need to select  the "Advanced..." button to see
the textfields for your proxy servers and ports.

There is a check box labelled "Use the same proxy server for all protocols"

If this check box is ticked, then all but the 1st textfield is disabled.
Toggling this check box allows you to see that the b./g colour of the
proxy textfields changes from "windows" to "3d objects" colour.

Choose "unusual" colours for these 2 items in the appearance dialog to
confirm this.

This is the way "JTextField" should behave in the Windows L&F, but it doesn't.
 
It appears that via java.awt.SystemColor we map the win32 native
COLOR_WINDOW property to  and we map
COLOR_3DFACE to java.awt.SystemColor.control, so probably control
should be the colour we use.
Of course the right highlighting contrast needs to be picked too.
Probably COLOR_3DLIGHT which maps to  java.awt.SystemColor.controlHighlight

Here is a simple test program illustrating the abberant behaviour.

import com.sun.java.swing.*;

public class Text 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("com.sun.java.swing.plaf.metal.MetalLookAndFeel");
	} catch (Throwable t) {
		t.printStackTrace();
      }
      Text text = new Text();
      text.show();
  }
  
  public Text() {

      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(b.createVerticalStrut(10));
      b.add(disabled);
      b.add(b.createVerticalStrut(10));
      b.add(uneditable);
      b.add(b.createVerticalStrut(10));
      b.add(disabled_and_uneditable);
      b.add(b.createVerticalStrut(10));

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

}



Name: krT82822			Date: 07/09/99


JPasswordField doesn't give any visual notification
that it is disabled. The following example displays
both a JTextField and JPasswordField, the JTextField
is "grayed" while the JPasswordField is not.

I am using Swing 1.1beta3.



import javax.swing.*;

public class test
{
        public static void main(String[] arg)
        {
                JFrame f=new JFrame("JPasswordFieldTest");
                f.getContentPane().setLayout(new java.awt.GridLayout(2,1));
                JTextField tf=new JTextField("JTextField");
                f.getContentPane().add(tf);
                tf.setEnabled(false);
                JPasswordField pf=new JPasswordField("JPasswordField");
                f.getContentPane().add(pf);
                pf.setEnabled(false);
                f.pack();
                f.show();
        }
}
(Review ID: 48361)
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: generic merlin-beta FIXED IN: merlin-beta INTEGRATED IN: merlin-beta
14-06-2004

WORK AROUND ###@###.### 2003-06-24 There really is a fairly simple workaround, namely to always call setEnabled() instead of, or together with, setEditable().
24-06-2003

EVALUATION This is fixed as a side-effect of fixing 4227348. BasicTextFieldUI now supports an attribute TextField.inactiveBackground which is by default the control color (like the metal laf). timothy.prinzing@eng 2000-03-01
01-03-2000