-
Bug
-
Resolution: Fixed
-
P4
-
1.3.0
-
beta
-
x86
-
windows_nt
Name: yyT116575 Date: 10/25/2000
java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class JFrame2 extends javax.swing.JFrame
{
public JFrame2()
{
setSize(300,100);
getContentPane().setLayout(new FlowLayout(FlowLayout.CENTER,5,5));
enabledCheckBox.setSelected(true);
enabledCheckBox.setText("enabled");
enabledCheckBox.setActionCommand("enabled");
getContentPane().add(enabledCheckBox);
textField.setText("11200");
getContentPane().add(textField);
passwordField.setText("blahblahblah");
getContentPane().add(passwordField);
SymItem lSymItem = new SymItem();
enabledCheckBox.addItemListener(lSymItem);
}
static public void main(String args[])
{
try {
//Create a new instance of our application's frame, and make it visible.
(new JFrame2()).setVisible(true);
}
catch (Throwable t) {
t.printStackTrace();
//Ensure the application exits with an error condition.
System.exit(1);
}
}
javax.swing.JCheckBox enabledCheckBox = new javax.swing.JCheckBox();
javax.swing.JTextField textField = new javax.swing.JTextField();
javax.swing.JPasswordField passwordField = new javax.swing.JPasswordField();
class SymItem implements java.awt.event.ItemListener
{
public void itemStateChanged(java.awt.event.ItemEvent event)
{
Object object = event.getSource();
if (object == enabledCheckBox)
{
try {
textField.setEnabled(enabledCheckBox.isSelected());
passwordField.setEnabled(enabledCheckBox.isSelected());
} catch (java.lang.Exception e) {}
}
}
}
}
When the JPasswordField is disabled, the foreground color doesn't change to
light gray as it should. It stays black like the original foreground color.
However, if the text in the JPasswordField is selected, then disabled, it turns
light gray as it should.
To reproduce the problem:
1) Uncheck the enabled arrow (the foreground color in the password field doesn't
change)
2) Enable the password field again
3) Select some of the text in the password field.
4) Disable the password field. (the foreground color of the selected password
text should turn gray while the unselected text remains black)
The bug is located in javax.swing.text.PasswordView
protected int drawUnselectedText(Graphics g, int x, int y, int p0, int p1) throws BadLocationException
{
Container c = getContainer();
if (c instanceof JPasswordField) {
JPasswordField f = (JPasswordField) c;
if (! f.echoCharIsSet()) {
return super.drawUnselectedText(g, x, y, p0, p1);
}
g.setColor(f.getForeground());
char echoChar = f.getEchoChar();
int n = p1 - p0;
for (int i = 0; i < n; i++) {
x = drawEchoCharacter(g, x, y, echoChar);
}
}
return x;
}
It should be:
g.setColor(unselected);
...instead of
g.setColor(f.getForeground());
(Review ID: 110735)
======================================================================