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

Disabled JTextField background should be control colour in Windows L&F



    • Subcomponent:
    • Resolved In Build:
    • CPU:
    • OS:


      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 {
      } catch (Throwable t) {
            Text text = new Text();
        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");
            Box b = new Box(BoxLayout.Y_AXIS);

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


      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");
                      JPasswordField pf=new JPasswordField("JPasswordField");
      (Review ID: 48361)


          Issue Links



              leifs Leif Samuelsson (Inactive)
              prr Philip Race
              0 Vote for this issue
              2 Start watching this issue