MOHAMED AHMED
MOHAMED AHMED

Reputation: 15

How to make any number entered into a jTextField appear in x's?

I made a GUI where a user enters a pin and hits enter. However the jTextField displays the actual numbers entered by the user and I'm trying to make it appear in x's but not able to do so. any help would be appreciated and if you can suggest anything :)

I tried this code for the text field but its wrong lol jTextField.setText("xxxx");

this is the code for one of the buttons code

if(evt.getSource() == buttonOne){
            if(jTextField.getText().length() < 4){
                if(clearField == 1){
                    jTextField.setText("0");
                    clearField = 0;
                } else{
                    jTextField.setText(jTextField.getText() + "1");
                }
            }
}
}

Thanks in advance

Upvotes: 0

Views: 80

Answers (1)

khelwood
khelwood

Reputation: 59146

Use a JPasswordField instead of a JTextField. This is designed to hide the entered text.

Upvotes: 5

Related Questions