-
Bug
-
Resolution: Fixed
-
P3
-
1.4.1, 1.4.2
-
1.2.1
-
tiger
-
x86
-
windows_nt, windows_2000
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.
======================================================================
- duplicates
-
JDK-5037097 JTextField does not show proper background color when disabled (Windows LAF)
- Closed
- relates to
-
JDK-5080144 REGRESSION: XP L&F: JTextField.setEditable() does not change background color
- Resolved
-
JDK-4919687 XP L&F: setBackground doesn't work on JtextField in JTable
- Resolved
-
JDK-4991597 Win L&F: Non editable and disabled text components have incorrect background col
- Resolved
-
JDK-4174290 Disabled JTextField background should be control colour in Windows L&F
- Resolved