Is it possible to change these bullets to asterisks in a passwordField? If so, how?
The bullet is unfortunately hard coded in the TextFieldSkin
but you can easily create a PasswordSkin by overriding the default, like this:
import com.sun.javafx.scene.control.skin.TextFieldSkin;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
public class PasswordSkin extends TextFieldSkin {
public PasswordSkin(TextField textField) {
super(textField);
}
protected String maskText(String txt) {
if (getSkinnable() instanceof PasswordField) {
int n = txt.length();
StringBuilder passwordBuilder = new StringBuilder(n);
for (int i = 0; i < n; i++)
passwordBuilder.append("*");
return passwordBuilder.toString();
} else {
return txt;
}
}
}
To use it, call setSkin
on your PasswordField
:
PasswordField input = new PasswordField();
input.setSkin(new PasswordSkin(input));
Alternatively, instead of setting the skin manually, you can include the following in your stylesheet:
.password-field {
-fx-skin: 'sample.PasswordSkin'
}
Make sure sample.PasswordSkin
is updated to reflect the fully qualified class name of your skin. Now every Scene or Node that has the stylesheet loaded will not need to have the skin configured manually.