Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 13 additions & 16 deletions src/java.desktop/share/classes/javax/swing/JPasswordField.java
Original file line number Diff line number Diff line change
Expand Up @@ -489,20 +489,19 @@ private String getEchoString(String str) {
* @since 1.6
*/
public String getAtIndex(int part, int index) {
String str = null;
if (part == AccessibleText.CHARACTER) {
str = super.getAtIndex(part, index);
return getEchoString(super.getAtIndex(part, index));
} else {
// Treat the text displayed in the JPasswordField
// as one word and sentence.
char[] password = getPassword();
if (password == null ||
index < 0 || index >= password.length) {
int length = getDocument().getLength();
if (index < 0 || index >= length) {
return null;
}
str = new String(password);
char[] password = new char[length];
Arrays.fill(password, getEchoChar());
return new String(password);
}
return getEchoString(str);
}

/**
Expand All @@ -523,8 +522,7 @@ public String getAtIndex(int part, int index) {
*/
public String getAfterIndex(int part, int index) {
if (part == AccessibleText.CHARACTER) {
String str = super.getAfterIndex(part, index);
return getEchoString(str);
return getEchoString(super.getAfterIndex(part, index));
} else {
// There is no word or sentence after the text
// displayed in the JPasswordField.
Expand All @@ -550,8 +548,7 @@ public String getAfterIndex(int part, int index) {
*/
public String getBeforeIndex(int part, int index) {
if (part == AccessibleText.CHARACTER) {
String str = super.getBeforeIndex(part, index);
return getEchoString(str);
return getEchoString(super.getBeforeIndex(part, index));
} else {
// There is no word or sentence before the text
// displayed in the JPasswordField.
Expand Down Expand Up @@ -606,14 +603,14 @@ public AccessibleTextSequence getTextSequenceAt(int part, int index) {
} else {
// Treat the text displayed in the JPasswordField
// as one word, sentence, line and attribute run
char[] password = getPassword();
if (password == null ||
index < 0 || index >= password.length) {
int length = getDocument().getLength();
if (index < 0 || index >= length) {
return null;
}
char[] password = new char[length];
Arrays.fill(password, getEchoChar());
String text = new String(password);
return new AccessibleTextSequence(0, password.length - 1,
getEchoString(text));
return new AccessibleTextSequence(0, password.length - 1, text);
}
}

Expand Down