JOptionPane, action listeners, and the Enter key.
I have a bit of a problem I'd like to solve. I have a login dialog, in the form of a JOptionPane. Its contents are an Object array including a label, a JTextField, another label, and a JPasswordField. It then has custom-labeled OK and Cancel buttons.
The idea is this. Dialog pops up, and if username-saving is OFF, the focus is in the user name field. If username-saving is ON, the user name is already in that field, so the focus should be on the password field. If the Enter key is pressed while in the username field, focus should move to the password field. If the Enter key is pressed while in the password field, it should hit the OK button.
Now, on the main form, I would employ an ActionListener to do this (and already have where necessary). But the JOptionPane stops everything happening in the background, as far as I'm aware. Is there any way to accomplish this rather complicated setup, without having to make some whole new window?
And also, how do I set default focus on one part of the Object array? If I try to single out the password field, it just goes back to the username field (but setting focus on a button works).