在JPasswordField中显示密码,而不是将0设置为echo char [英] Displaying the password in a JPasswordField rather than setting 0 as an echo char
问题描述
如何显示JPasswordField的文本而不是将0设置为echo char?
How do I display the text of a JPasswordField rather than set 0 as an echo char?
Java Docs说:
Java Docs says:
设置为0的值表明您希望看到的文字,因为它是类型化的,类似于标准JTextField的行为。
Setting a value of 0 indicates that you wish to see the text as it is typed, similar to the behavior of a standard JTextField.
以下结果导致不兼容类型错误
The following results in an Incompatible types error
outField.setEchoChar(0);
wheras
outField.setEchoChar('0');
只需设置0作为回显字符(每个数字显示0)。
simply sets 0 as the echo char (displays 0s for every digit).
在JTextField上使用JPasswordField的原因是我想更改echo char并用其他方法隐藏密码。
The reason for using JPasswordField over JTextField is that I want to change the echo char and hide the password with another method.
谢谢!
推荐答案
这样做:
outField.setEchoChar((char)0);
如果你这样做:
outField.setEchoChar(0);
然后0是整数,而不是char,并且该方法需要char。
then 0 is an integer, not a char, and the method requires a char.
如果你这样做:
outField.setEchoChar('0');
然后'0'相当于(char)48。
then '0' is equivalent to (char)48.
这篇关于在JPasswordField中显示密码,而不是将0设置为echo char的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!