I have created a password field using JOptionPane
. When I run the program, the JOptionPane
comes up and looks great, however the focus always goes to the OK button. I want the focus start on the password field. I've tried requestFocus()
, requestFocusInWindow()
, but this doesn't seem to work. Is there something special that I need to go to get the focus on password field?
See my code below :
JPasswordField pf = new JPasswordField();
pf.requestFocusInWindow();
int okCxl = JOptionPane.showConfirmDialog(null, pf, "ENTER SUPERUSER PASSWORD", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);