문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top