I am trying to change background colors of a JPasswordField in Java Swing (Netbeans).
Here\'s what I have:
private void pstxtPasswordKeyPressed(java.
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.