AWT/SWT 中的 iPhone 密码字段?
我想为我的 eclipse 产品创建一个特殊的密码对话框,它与屏幕键盘一起使用。
如果我可以使用像 iPhone 密码字段这样的组件,那就太好了。在此字段中,添加的字符会显示一秒钟,然后会转换为“*”字符以隐藏完整的密码。
是否存在 jar/库,这是在 AWT 或 SWT 中实现的吗?
编辑:
我可以尝试从头开始实现它(SWT),但对于这些,我必须为密码文本组件创建一个非常特殊且复杂的 KeyListener。我必须捕获 keyReleased 事件并将字符手动设置到字段中。
到目前为止,我无法在网络上找到任何库。 也欢迎提出如何实施的建议。
I want to create a special Password Dialog for my eclipse product, which is used with an on screen keyboard.
It would be very nice, if i could use a component like the IPhone Password field. In this field, the added character is shown for a second and after the second it is converted into the '*' character for hiding the complete password.
Did a jar/library exists, this is implemented in AWT or SWT?
Edit:
I could trying to implement it from scratch (SWT), but for these i would have to create a very special and complicated KeyListener for the password Text component. I would have to catch the keyReleased event and set the characters manually into the field.
So far i was not able to find any libraries in the web. Suggestion how this can be implemented are welcome too.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这并不是一个完整的答案,而不是一个讨论的开始,我不知道有任何开箱即用的小部件可以做到这一点。
我的第一个想法是继承 swt Text 小部件并覆盖 setEchoChar 等人,但是在查看代码之后,这似乎并不可行,因为这个方法只是一个包装器:
如果有人知道操作系统特定的低级实施,这可能会有所帮助。
无论如何,采取不同的方法。我会避免使用 KeyListener 并在 Text-Widget 上使用 ModifyListener。
然后,您可以构建一个包装器,使用此侦听器捕获输入的文本,将其附加到本地保存的字符串/字符串缓冲区(或例如 Eclipse Preferencestore),并使用 setText(String s) 将修改后的全文发送到文本小部件,替换所有文本除最后一个回显字符(例如 *)之外的字符。
这有点拼凑,但应该可行。
不那么简单的一点是 1 秒计时,但不会影响整个视图......
This is not really a full answer, rather than a discussion starter and I don't know of any out-of-the-box widgets which can do that.
My first idea was to inheriting the swt Text widget and overriding setEchoChar et al., but after looking at the code this doesn't really seem feasible, because this method is merely a wrapper around:
If anyone would know the OS specific low-level implementation, that might be helpful.
Anyway, on to a different approach. I would avoid the KeyListener and use a ModifyListener on the Text-Widget.
You could then build a wrapper which catches the entered text using this listener, appends it to a locally held string/stringbuffer (or e.g. the Eclipse Preferencestore) and send a modified full text to the Text widget using setText(String s), replacing all characters except the last by an echo character (e.g. *).
This is a bit of a kludge, but it should work.
The not so straightforward bit is the 1 second timing, without stalling the whole view...
根据 Jules 的说法,以下代码可以正常工作。
代码又快又快,我希望有一个更线程安全的解决方案。
关键事件会被缓存,因此您可以添加更多字符,即使在线程等待时也是如此。
另一个问题是游标处理。当您设置文本时,光标始终移动到第一个位置。
我认为当它起作用时,它非常接近 iPhone 的解决方案。
Depending on what Jules said the following code is some kind of working.
The code is quick and fast and i would like to have a more thread safe solution.
Key Events are cached, so you can add more characters, also when the Thread is waiting.
Another Problem is the Cursor handling. the Cursor always moves to the first position, when you set the Text.
I think when this is working it is very near to the iphone solution.