问题
TextField password = new TextField("", "Pass Word", 15, TextField.PASSWORD);
CheckBox maskAndUnmaskCheck = new CheckBox();
maskAndUnmaskCheck.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
if(maskAndUnmaskCheck.isSelected()) {
password.setConstraint(TextField.ANY);
} else{
password.setConstraint(TextField.PASSWORD);
}
}
});
We are using the above code to display the password without mask i.e showing the text that what he types when a user selects the check box.
The above code is working perfectly with Android mobiles, the code is not working on iPhone devices.
Is there any way to achieve the same in on iPhone too.
Do I need any code changes for iOS?
回答1:
One thing I noticed that is missing there is: repaint()
or revalidate()
.
final TextField password = new TextField("","Pass Word",15,TextField.PASSWORD);
CheckBox maskAndUnmaskCheck = new CheckBox();
maskAndUnmaskCheck.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
if(maskAndUnmaskCheck.isSelected()){
password.setConstraint(TextField.ANY);
} else {
password.setConstraint(TextField.PASSWORD);
}
if(password.isEditing()) {
password.stopEditing();
password.startEditingAsync();
} else {
password.getParent().revalidate();
}
}
});
来源:https://stackoverflow.com/questions/42807405/codename-one-mask-and-unmask-password-field-on-ios