开发者

how to listen to Enter button when using JOptionPane.showOptionDialog

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,
            JOptionPan开发者_运维知识库e.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?


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.

Dialog Focus should help you out.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜