Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在inputDialog中键入时隐藏文本 if(e.getSource()==credLimit){//用户更改信用额度的事件处理 字符串输入=JOptionPane.showInputDialog(null,“输入密码”); setEchoChar('*');_Java_User Interface_Input_Dialog - Fatal编程技术网

Java 如何在inputDialog中键入时隐藏文本 if(e.getSource()==credLimit){//用户更改信用额度的事件处理 字符串输入=JOptionPane.showInputDialog(null,“输入密码”); setEchoChar('*');

Java 如何在inputDialog中键入时隐藏文本 if(e.getSource()==credLimit){//用户更改信用额度的事件处理 字符串输入=JOptionPane.showInputDialog(null,“输入密码”); setEchoChar('*');,java,user-interface,input,dialog,Java,User Interface,Input,Dialog,这将隐藏您输入的文本 if(e.getSource() == credLimit){ // event handling for user to change credit limit String input = JOptionPane.showInputDialog(null, "Enter Password"); input.setEchoChar('*'); <<-----here is what I have tried if(input.equal

这将隐藏您输入的文本

if(e.getSource() == credLimit){ // event handling for user to change credit limit
    String input = JOptionPane.showInputDialog(null, "Enter Password");
    input.setEchoChar('*'); <<-----here is what I have tried
    if(input.equals(password)) { // password check for credit limit
        double credLimitTotal = Double.parseDouble(changeCredLimit.getText());
        JOptionPane.showMessageDialog(null, currentCreditCard.changeCreditLimit(credLimitTotal));
        changeCredLimit.setText("");
    }
}

您不能在
输入对话框中直接隐藏字符。您可以使用默认情况下隐藏字符的创建自己的
对话框。请尝试以下代码:

<input type="password" name="txtPassword" placeholder="Enter Password"/>

用于更改键入时显示给用户的字符。

要隐藏文本框中的文本,您需要像这样使用JPassword

Box box = Box.createHorizontalBox();

JLabel jl = new JLabel("Password: ");
box.add(jl);

JPasswordField jpf = new JPasswordField(24);
box.add(jpf);

int button = JOptionPane.showConfirmDialog(null, box, "Enter your password", JOptionPane.OK_CANCEL_OPTION);

if (button == JOptionPane.OK_OPTION) {
    char[] input = jpf.getPassword();
    if(input.equals(password)) {
        ...
    }
}
这里是到的链接,以了解更多详细信息


这是HTML,不是Java
passwordField = new JPasswordField(10);
passwordField.setActionCommand(OK);