如何将用户输入的文本隐藏到密码JTextField中? [英] How do I hide the text that the user enters into a password JTextField?
问题描述
我有一个类要求用户名和密码来验证应用程序中的用户。
I have a class that asks for a username and password to autenticate a user in the application.
在其中,我有2个 JTextField 对象,一个用于用户名输入,另一个用于密码输入。
Inside it, I have 2 JTextField objects, one for the username input and one for the password input.
JTextField userNameTextField = new JTextField(20);
JTextField pswdTextField = new JTextField(20);
它工作正常但我的问题是,当用户在pswdTextField中输入密码时,密码显示在里面。我希望通过在构成插入密码的每个字母上显示一个点,星号或类似物来隐藏它。
It works fine but my problem is that, when the user writes the password in the pswdTextField, the password is shown inside it. I want to hide it by showing a dot, asterisk or similar for each letter that makes up the inserted password.
这是如何完成的?
推荐答案
不使用JTextField,而是为pswdTextField使用JPasswordField
Instead of using a JTextField, use a JPasswordField for your pswdTextField
这篇关于如何将用户输入的文本隐藏到密码JTextField中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!