This is my code for creating login dialog but I want to login automatically on Enter key press which is not getting done with this code. I have tried getRootPane().setDefaultButton(..);
but I don't have JButton object.
String _options = {"ok", "Exit"};
JOptionPane pane = new JOptionPane(this, JOptionPane.PLAIN_MESSAGE, JOptionPane.DEFAULT_OPTION, null, _options, null);
JDialog dialog = pane.createDialog("Login");
dialog.setAlwaysOnTop(true);
dialog.setVisible(true);
dialog.requestFocus();
dialog.toFront();
I am thinking of setting default button but is there any way to get JButton object from JOptionpane?
Secondly we can set
JOptionPane pane = new JOptionPane(this, JOptionPane.PLAIN_MESSAGE, JOptionPane.DEFAULT_OPTION, null, _options, _options[0]); //set to _options[0]
but here the problem is it transfers the focus to "ok" button and name is not focusable? how can this be solved?