I would to know if there is a way to mask the text of a TextArea in JavaFX.
For example, masking the text using the 'bullet' password character like PasswordField. For TextField, there is the maskText() method that works well. This method is not useful for TextArea.
What can I do?
NB: I want that getText() and setText() method must work with the clear text, not with the masked text. Just like PasswordField works.
EDIT
That is the approach I used to achieve the result, but unfortunately unsuccessfully.
My custom TextArea class:
public class PasswordArea extends TextArea {
@Override
protected Skin<?> createDefaultSkin() {
return new PasswordAreaSkin(this); //my custom skin
}
}
the custom skin used for the custom TextArea:
public class PasswordAreaSkin extends TextAreaSkin {
public PasswordAreaSkin(PasswordArea control) {
super(control);
}
//here I override the maskText method to mask the text
@Override
protected String maskText(String text) {
int n = text.length();
StringBuilder passwordBuilder=new StringBuilder(n);
for(int i = 0; i < n; i++) {
passwordBuilder.append('\u2022'); //append 'bullet' char
}
return passwordBuilder.toString();
}
}
