Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codename One - Mask and Unmask Password Field on iOS

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?

like image 311
user2243420 Avatar asked Dec 09 '25 08:12

user2243420


1 Answers

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(); 
        }
    }
}); 
like image 175
Diamond Avatar answered Dec 10 '25 21:12

Diamond



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!