Displaying the password in a JPasswordField rather than setting 0 as an echo char

前端 未结 5 777
礼貌的吻别
礼貌的吻别 2021-01-14 11:37

How do I display the text of a JPasswordField rather than set 0 as an echo char?

Java Docs says:

Setting a value of 0 indicates that you wish

相关标签:
5条回答
  • 2021-01-14 11:49

    Do this:

    outField.setEchoChar((char)0);
    

    If you do this:

    outField.setEchoChar(0);
    

    then 0 is an integer, not a char, and the method requires a char.

    If you do this:

    outField.setEchoChar('0');
    

    then '0' is equivalent to (char)48.

    0 讨论(0)
  • 2021-01-14 11:55

    Use the char with value 0, not the number 0, or the char '0':

        outField.setEchoChar((char)0);
    
    0 讨论(0)
  • 2021-01-14 11:56

    When you do this:

    outField.setEchoChar(0);
    

    you're trying to pass an int into the method, and this isn't allowed since it expects a char type. Instead try

    outField.setEchoChar((char)0);
    
    0 讨论(0)
  • 2021-01-14 12:01

    Try it out like this......

    outField.setEchoChar((char)0);
    
    0 讨论(0)
  • 2021-01-14 12:06

    try outField.setEchoChar('\0');

    0 讨论(0)
提交回复
热议问题