如何在Jpasswordfield中添加眼睛符号?
如何使用Java Swing在Java应用程序中添加眼睛符号?
How can I add an eye symbol in my java application using java swing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
如何使用Java Swing在Java应用程序中添加眼睛符号?
How can I add an eye symbol in my java application using java swing?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(1)
您可以实现多种方式。在以下代码中,我创建a jpanel 包含a 和a jlabel> jlabel 显示“ EYE” ICON。我删除 border> border 来自
代码>。 (请注意,默认情况下,
。当鼠标指针在jlabel
没有边框。)我在jpanel
中添加了一个边框,使其看起来像一个单个文本字段。我从接受的答案中得到了这个想法在Jtextfield(Java)内。最后,我添加a mouselisteristenerjlabel
内部时,jpasswordfield
中的文本是可读的,并且鼠标指针不在jlabel
中时,文本在jpasswordfield
中显示为星号字符串,即*
。You can implement this several ways. In the below code, I create a JPanel which contains a JPasswordField and a JLabel which displays an "eye" icon. I remove the border from the
JPasswordField
. (Note that, by default, aJLabel
does not have a border.) And I add a border to theJPanel
that makes it look like a single, text field. I got that idea from the accepted answer to How to put a JButton inside a JTextField (Java). Finally, I add a MouseListener to theJLabel
. When the mouse pointer is inside theJLabel
, the text in theJPasswordField
is readable and when the mouse pointer is not inside theJLabel
, the text in theJPasswordField
is displayed as a string of asterisk characters, i.e.*
.