如何在选项按钮单击时停止关闭joptionpane

时间:2015-02-26 10:59:09

标签: joptionpane

伙计们我想在我的项目中添加密码选项窗格

    String password;
    JTextField jtf = null;
    JPasswordField passwordField = new JPasswordField();
    passwordField.setEchoChar('*');
    JOptionPane jop = null;

    Object[] obj = {"Please enter the password:\n\n", passwordField, jtf};
    Object stringArray[] = {"OK", "Cancel"};
    if (jop.showOptionDialog(null, obj, "Confirm",
            jop.YES_NO_OPTION, jop.QUESTION_MESSAGE, null, stringArray, obj) == jop.YES_OPTION) {

        System.out.println("OK");
    } else {
        System.out.println("CLOSE");
    }

我想在按钮点击时关闭此窗格请帮助我:)

1 个答案:

答案 0 :(得分:0)

你可以试试这个:

   while(true){
    if (jop.showOptionDialog(null, obj, "Confirm",
            jop.YES_NO_OPTION, jop.QUESTION_MESSAGE, null, stringArray, obj) == jop.YES_OPTION) {

        System.out.println("OK");
    } else {
        System.out.println("CLOSE");
    }
}