在Netbeans中我已经在面板中放置了JpasswordField,你能告诉我如何删除JpasswordField中出现的默认星号吗?
答案 0 :(得分:0)
要删除或更改显示的默认字符而不是字母,请使用JPasswordField#setEchoChar(char c)
方法:
示例:
import java.awt.BorderLayout;
import javax.swing.*;
public class Example {
public static void main(String args[]) {
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Box rowOne = Box.createHorizontalBox();
rowOne.add(new JLabel("Username"));
rowOne.add(new JTextField());
Box rowTwo = Box.createHorizontalBox();
rowTwo.add(new JLabel("Password"));
JPasswordField jpassword = new JPasswordField();
rowTwo.add(jpassword);
f.add(rowOne, BorderLayout.NORTH);
f.add(rowTwo, BorderLayout.SOUTH);
f.setSize(300, 200);
f.setVisible(true);
jpassword.setEchoChar('#');
System.out.println(jpassword.getEchoChar());
}
}