mardi 17 février 2015

Textfield doesn't maintain focus (AncestorListener)


Vote count:

0




I am using Camick's code to request focus on my JPasswordField (at the end): http://ift.tt/1LaGgjY


The focus is on the password field the first time the showConfirmDialog appears, but when the dialog appears the second time (either due to wrong password, or clicking the button again), the focus is moved to 'OK', and then back to the password field the next time. Here is my code...



int resp;
String givenPwd;
JPasswordField pwd = new JPasswordField(10);

do {
pwd.setText("");
pwd.addAncestorListener(new RequestFocusListener());
diagResp = JOptionPane.showConfirmDialog(null, pwd, "Enter Password", JOptionPane.OK_CANCEL_OPTION);
givenPwd = new String(pwd.getPassword());

if (resp != JOptionPane.OK_OPTION) { return false; }
} while (!givenPwd.equals(cmpPwd));


asked 57 secs ago







Textfield doesn't maintain focus (AncestorListener)

Aucun commentaire:

Enregistrer un commentaire