Neeraj singh
Neeraj singh

Reputation: 255

How to enter a special character as a Password in the JTextField of the swing component?

When we enter password in any account the characters are not shown to us. I created a JTextField whose label is "password". What can I do so that when I enter characters in this JTextField they are shown like "***********" ?

Upvotes: 2

Views: 4440

Answers (3)

Richard Flores
Richard Flores

Reputation: 71

Use JPasswordField but you can use this code to convert Char to String;

String password = String.valueOf(jPasswordField.getPassword());

Upvotes: 0

Kumar Vivek Mitra
Kumar Vivek Mitra

Reputation: 33544

I think the solution to the problem is using JPasswordField

See this documentation:

http://docs.oracle.com/javase/6/docs/api/javax/swing/JPasswordField.html

See these tutorials:

www.java2s.com/Tutorial/Java/0240_Swing/0300_JPasswordField.htm

Upvotes: 3

Nate W.
Nate W.

Reputation: 9259

Don't use a normal JTextField, use a JPasswordField.

Upvotes: 9

Related Questions