Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to display characters in jPasswordField rather than * sign in java?

I am working with jPasswordField in java in order to make a log in system.

I have used jTextField for name input and jPasswordField for password. I want to create an option of "Show Characters" in my program that may allow the user to view the characters he has typed in passwordfield.

I have tried

  1. retrieving data from password field
  2. converting it into string
  3. displaying that string in passwordfield using .setText() method

But this did not work, as it displays everything in esteric (*****) form. Please help...

like image 401
Rozeena Arif Hussain Avatar asked Dec 28 '13 09:12

Rozeena Arif Hussain


1 Answers

hidePasswordCheckbox.addItemListener(new ItemListener() {
    public void itemStateChanged(ItemEvent e) {
        if (e.getStateChange() == ItemEvent.SELECTED) {
            httpProxyPassword.setEchoChar('*');
        } else {
             httpProxyPassword.setEchoChar((char) 0);
        }
    }
});

You have to use httpProxyPassword.setEchoChar((char) 0); for that. Here httpProxyPassword is a name of textbox you can use as per your's.

like image 103
Java Curious ღ Avatar answered Oct 26 '22 23:10

Java Curious ღ