Skip to content

Commit 37bd4fb

Browse files
committed
6852577: Only for Nimbus LAF UIManager.get("PasswordField.echoChar") is null
Reviewed-by: tr, aivanov
1 parent d4c9a88 commit 37bd4fb

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
lines changed

src/java.desktop/share/classes/javax/swing/plaf/synth/SynthLookAndFeel.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,8 @@ public UIDefaults getDefaults() {
728728
SwingUtilities2.getSystemMnemonicKeyMask())
729729
});
730730

731+
table.put("PasswordField.echoChar", '*');
732+
731733
// enabled antialiasing depending on desktop settings
732734
flushUnreferenced();
733735
SwingUtilities2.putAATextInfo(useLAFConditions(), table);

src/java.desktop/share/classes/javax/swing/plaf/synth/SynthPasswordFieldUI.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,19 @@ protected String getPropertyPrefix() {
6767
return "PasswordField";
6868
}
6969

70+
/**
71+
* Installs the necessary properties on the JPasswordField.
72+
*/
73+
@Override
74+
protected void installDefaults() {
75+
super.installDefaults();
76+
String prefix = getPropertyPrefix();
77+
Character echoChar = (Character)UIManager.getDefaults().get(prefix + ".echoChar");
78+
if (echoChar != null) {
79+
LookAndFeel.installProperty(getComponent(), "echoChar", echoChar);
80+
}
81+
}
82+
7083
/**
7184
* Creates a view (PasswordView) for an element.
7285
*
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
/*
24+
* @test
25+
* @bug 6852577
26+
* @summary Verifies PasswordField.echoChar is not null for Nimbus L&F
27+
* @run main PasswordFieldTest
28+
*/
29+
30+
import javax.swing.UIManager;
31+
import javax.swing.SwingUtilities;
32+
import javax.swing.UnsupportedLookAndFeelException;
33+
34+
public class PasswordFieldTest {
35+
private static void setLookAndFeel(UIManager.LookAndFeelInfo laf) {
36+
try {
37+
UIManager.setLookAndFeel(laf.getClassName());
38+
} catch (UnsupportedLookAndFeelException ignored) {
39+
System.out.println("Unsupported L&F: " + laf.getClassName());
40+
} catch (ClassNotFoundException | InstantiationException
41+
| IllegalAccessException e) {
42+
throw new RuntimeException(e);
43+
}
44+
}
45+
46+
public static void main(String[] args) throws Exception {
47+
SwingUtilities.invokeAndWait(() -> {
48+
for (UIManager.LookAndFeelInfo laf :
49+
UIManager.getInstalledLookAndFeels()) {
50+
System.out.println("Testing L&F: " + laf.getClassName());
51+
setLookAndFeel(laf);
52+
53+
System.out.println("Echo char: " +
54+
UIManager.get("PasswordField.echoChar"));
55+
if (UIManager.get("PasswordField.echoChar") == null) {
56+
throw new RuntimeException(
57+
"PasswordField.echoChar returns null for " +
58+
laf.getClassName());
59+
}
60+
}
61+
});
62+
}
63+
}

0 commit comments

Comments
 (0)