Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Getting password in string format directly from JPasswordField

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading