-
Bug
-
Resolution: Cannot Reproduce
-
P4
-
None
-
1.1.7, 1.3.0
-
x86
-
windows_nt, windows_2000
Name: yyT116575 Date: 03/12/2001
C:\>java -version
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)
The cursor for a password field does not seem to be correctly reset for a
when the field is cleared using setText(""). Please run the following code to
see this problem.
/**
* Simple class to demonstrate a problem (?) with JPasswordField.
* Problem detected on an NT machine running Java version:
*
* C:\>java -version
* 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)
*
* The problem: The cursor does not seem to be correctly reset for a
* JPasswordField when the field is cleared using setText("")
*
* To replicate: Run this class. A dialog is shown 3 times. It prompts
* for a user-id and a password.
*
* When appears for the first time, enter any text (say 5 or 6 chars)
* at BOTH the user-id and password fields. Press the OK button.
*
* When the dialog appears for the SECOND time, enter some text at
* the user-id field and then TAB (ie: do NOT use the mouse) to the
* password field. Note that the cursor is NOT at the start of the
* field, but is still at the end of the previously entered text for
* the field, even through the text is no longer displayed!!
*
* The third display of the dialog is just an example of using the
* Caret of the JPasswordField to force it to display correctly when
* you TAB to the password field.
*
* This problem may (??) be related to bug 4139009
*/
import java.awt.*;
import javax.swing.*;
import javax.swing.text.*;
public class TestPwdProblem extends JFrame {
private JPanel TestPwdPanel;
private JTextField idText;
private JPasswordField pwdText;
public static void main(String[] args) {
int val;
TestPwdProblem tpp = new TestPwdProblem();
val = JOptionPane.showOptionDialog(tpp, tpp.getPanel(), null,
JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE,
null, null, null);
tpp.resetThatFails(); // 'Clear' the user-id and password fields!
val = JOptionPane.showOptionDialog(tpp, tpp.getPanel(), null,
JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE,
null, null, null);
tpp.resetThatWorks();
val = JOptionPane.showOptionDialog(tpp, tpp.getPanel(), null,
JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE,
null, null, null);
}
public TestPwdProblem() {
TestPwdPanel = new JPanel();
idText = new JTextField(20);
pwdText = new JPasswordField(20);
JLabel idLabel = new JLabel("User id");
JLabel pwdLabel = new JLabel("Password");
GridBagLayout gbl = new GridBagLayout();
GridBagConstraints gbc = new GridBagConstraints();
TestPwdPanel.setLayout(gbl);
gbc.fill = GridBagConstraints.NONE;
gbc.anchor = GridBagConstraints.WEST;
gbc.insets = new Insets(4, 4, 4, 10);
gbl.setConstraints(idLabel, gbc);
TestPwdPanel.add(idLabel);
gbc.gridwidth = GridBagConstraints.REMAINDER;
gbc.insets = new Insets(4, 0, 4, 4);
gbl.setConstraints(idText, gbc);
TestPwdPanel.add(idText);
gbc.gridwidth = 1;
gbc.insets = new Insets(0, 4, 4, 10);
gbl.setConstraints(pwdLabel, gbc);
TestPwdPanel.add(pwdLabel);
gbc.gridwidth = GridBagConstraints.REMAINDER;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(0, 0, 4, 4);
gbl.setConstraints(pwdText, gbc);
TestPwdPanel.add(pwdText);
}
public JPanel getPanel() {
return (TestPwdPanel);
}
public void resetThatFails() {
idText.setText("");
pwdText.setText("");
}
public void resetThatWorks() {
idText.setText("");
pwdText.setText("");
Caret c = pwdText.getCaret();
c.setDot(0);
}
}
(Review ID: 118355)
======================================================================
- duplicates
-
JDK-4182961 JPasswordField (swing-1.1.b3), once set cannot be cleared
-
- Closed
-
- relates to
-
JDK-4226384 JTextField.setText() from EventDispatchThread ignores alignment?
-
- Closed
-
-
JDK-4201999 JTextArea's don't automatically scroll when appending() to them.
-
- Resolved
-
-
JDK-4834399 invokeLater causes JScrollPane to scroll to bottom at creation
-
- Closed
-