Echo jpassword character once and then hide it

核能气质少年 提交于 2019-12-11 02:57:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!