简体   繁体   中英

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 "***********" ?

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

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM