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

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

XMLWordPrintable

    • beta
    • x86
    • windows_nt

      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)
      ======================================================================

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: