JPasswordField KeyPress string length error?

后端 未结 5 1445
名媛妹妹
名媛妹妹 2020-12-20 21:04

I am trying to change background colors of a JPasswordField in Java Swing (Netbeans).

Here\'s what I have:

private void pstxtPasswordKeyPressed(java.         


        
5条回答
  •  囚心锁ツ
    2020-12-20 21:47

    As an aside, examine the length of the array returned by getPassword(), rather than the length of a String constructed from that array. The String is a security risk, as it will be stored for an indefinite time with the easily found name userPassword.

    Addendum: Here's a related example of Robin's suggestion to use DocumentListener. I'm guessing that your key listener is seeing the KeyEvent before the JPasswordField has processed it.

提交回复
热议问题