我在尝试使用亚洲复合字符时遇到 JPasswordField 组件行为不一致的问题。
我的代码是:
final JCheckBox visiblePassword = new JCheckBox(); // show/hide password checkbox
JPasswordField passwordField = new JPasswordField();
passwordField.setPreferredSize(new Dimension(200, 25));
final char echoChar = passwordField.getEchoChar();
visiblePassword.addActionListener(new ActionListener() // show/hide password
{
public void actionPerformed(ActionEvent evt)
{
if(visiblePassword.isSelected()) passwordField.setEchoChar((char)0);
else passwordField.setEchoChar(echoChar);
}
});
我的目标是允许输入密码中的所有字符。
但是:
Windows 8 - 它根本不起作用(只允许使用拉丁字符 - IME 不起作用)。
Mac OS X - 允许使用韩文字符(但不会将它们连接到一个字符),日文和中文根本不起作用。
我可以在此处找到针对其他平台(例如 iOS)的此问题的讨论和解决方案:
Selecting language of the keyboard for UITextField with secureTextEntry
但是对于 Java swing 来说没有什么。
因此,在开始实现“JPasswordField”的自定义版本之前,我想问:
有人解决这个问题吗?或者您知道其他一些组件(例如 JPasswordField)但适合我的需求吗?
最佳答案
您知道这个链接吗? JPasswordField (Java Platform SE 8 )
NOTE: By default, JPasswordField disables input methods; otherwise, input characters could be visible while they were composed using input methods. If an application needs the input methods support, please use the inherited method, enableInputMethods(true).
关于java - 在亚洲语言(韩语、日语、中文)的 Java swing (JPasswordField) 中设置密码不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28829322/