问题
In my swing application I want to echo jpassword field character for some time (1 second) and then again hide it. I want to do it character by character after user inputs a character (When user inputs a character, show it, then hide it. Then for all input characters repeat this). Can someone tell me is it possible, if yes how? Thanks in advance!
回答1:
It's not very complicated, you can disable the masking characters when you set this value to “0″ with this method: setEchoChar((char) 0)
pass.getDocument().addDocumentListener(new DocumentListener() {
public void changedUpdate(DocumentEvent e) {
unhide();
}
public void removeUpdate(DocumentEvent e) {
unhide();
}
public void insertUpdate(DocumentEvent e) {
unhide();
}
public void unhide(){
pass.setEchoChar((char) 0);//display password
//here your timer
pass.setEchoChar('*');//hide with '*'
}
});
The code above shows you a first idea of what you should do. You'll have to use a thread to wait for the desired time.
回答2:
I came across this which may be a good start as it displays the last char entered and shows the rest of the password is masked but doesn't hide it after a set time so you would probably need to implement an event to hide after set time Check it out here
来源:https://stackoverflow.com/questions/23780963/echo-jpassword-character-once-and-then-hide-it