diff --git a/gemsfx/src/main/java/com/dlsc/gemsfx/skins/EnhancedPasswordFieldSkin.java b/gemsfx/src/main/java/com/dlsc/gemsfx/skins/EnhancedPasswordFieldSkin.java index 4bd032a0..32a8f500 100644 --- a/gemsfx/src/main/java/com/dlsc/gemsfx/skins/EnhancedPasswordFieldSkin.java +++ b/gemsfx/src/main/java/com/dlsc/gemsfx/skins/EnhancedPasswordFieldSkin.java @@ -3,6 +3,7 @@ import com.dlsc.gemsfx.EnhancedPasswordField; import javafx.beans.binding.StringBinding; import javafx.scene.Node; +import javafx.scene.control.TextField; import javafx.scene.text.Text; import java.util.Optional; @@ -10,11 +11,8 @@ public abstract class EnhancedPasswordFieldSkin extends CustomTextFieldSkin { - private final EnhancedPasswordField control; - public EnhancedPasswordFieldSkin(EnhancedPasswordField control) { super(control); - this.control = control; // find the text nodes Set nodes = control.lookupAll(".text"); @@ -43,12 +41,23 @@ protected String computeValue() { @Override protected String maskText(String txt) { - if (control == null || !control.isShowPassword()) { - int n = txt.length(); - char echoChar = control != null ? control.getEchoCharSafe() : EnhancedPasswordField.DEFAULT_ECHO_CHAR; - return String.valueOf(echoChar).repeat(n); + TextField skinnable = getSkinnable(); + int len = txt.length(); + if (skinnable == null) { + return getDefaultMaskText(len); + } + + if (skinnable instanceof EnhancedPasswordField passwordField) { + if (passwordField.isShowPassword()) { + return txt; + } + return String.valueOf(passwordField.getEchoCharSafe()).repeat(len); } - return txt; + return getDefaultMaskText(len); + } + + private String getDefaultMaskText(int len) { + return String.valueOf(EnhancedPasswordField.DEFAULT_ECHO_CHAR).repeat(len); } } \ No newline at end of file