Java – displays the password in jpasswordfield instead of setting 0 to echo char

How do I display the text of jpasswordfield instead of setting 0 to echo char?

Java docs says:

The following results in incompatible type errors

outField.setEchoChar(0);

wheras

outField.setEchoChar('0');

Just set 0 to echo char (each number displays 0)

The reason for using jpasswordfield on jtextfield is that I want to change echo char and use other methods to hide the password

thank you!

Solution

Do this:

outField.setEchoChar((char)0);

If you do this:

outField.setEchoChar(0);

Then 0 is an integer, not char, and the method requires char

If you do this:

outField.setEchoChar('0');

Then '0' is equivalent to (char) 48

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>