1
當我使用:怎麼聽回車鍵使用JOptionPane.showOptionDialog
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;
獲取口令,但這不能聽回車鍵。 我知道如果我將選項參數設置爲空,可以讓對話框聽取「輸入」按鈕,但如果我這樣做,則顯示時對話框不會聚焦到文本框。
有人可以幫助我嗎?