how to listen to Enter button when using JOptionPane.showOptionDialog
Posted
by
MemoryLeak
on Stack Overflow
See other posts from Stack Overflow
or by MemoryLeak
Published on 2011-01-05T05:54:42Z
Indexed on
2011/01/05
6:53 UTC
Read the original article
Hit count: 168
java
|joptionpane
I use:
char[] password = null;
JPasswordField jpf = new JPasswordField(30);
java.lang.Object [] messageInput = { prompt, jpf };
java.lang.Object [] options = { jpf , "OK", "Cancel"};
int result = JOptionPane.showOptionDialog(null, messageInput, title,
JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE,
null, options, "");
JOptionPane.showMessageDialog(null,
result);
if (result == 1) {
password = jpf.getPassword();
}
else if(result == JOptionPane.CANCEL_OPTION)
{
}
return password;
to get password, but this can not listen to the Enter button. I know if I set the options parameter to null, can make the dialog listen to "enter" button, but if I do that, the dialog don't focus to the textbox when show up.
Can someone help me on this ? Thanks in advance !
© Stack Overflow or respective owner