I was taking input from a password field using JPasswordField. Here is the code snippet:
JPasswordField enterNewPassword = new JPasswordField ();
enterNewPassword.setBounds( 150,70,100,20);
String password = String.valueOf(enterNewPassword.getPassword());
The above code gives me the password as string after adding the function valueOf. Is there any other way to retrieve the password as string directly?
CodePudding user response:
I would suggest you create a JTextField and it should point to a JPasswordField.
So use this:
JTextField enterNewPassword = new JPasswordField();
This will hide the text input and will automatically convert the password to plain string also. No conversion is required