gpt4 book ai didi

swt - 如何动态隐藏或显示 SWT 密码

转载 作者:行者123 更新时间:2023-12-04 02:08:19 26 4
gpt4 key购买 nike

在我的登录对话框中,有一个按钮:

Text pwdT = new Text(container, SWT.BORDER|SWT.PASSWORD);
Button plainBtn = new Button(container,SWT.CHECK);

如果我选择 plainBtn , 我要密码显示在 pwdT改为纯文本而不是密文?有谁知道如何做到这一点?

最佳答案

setEchoChar()方法可用于控制是否应显示输入的字符。
要显示实际输入的字符,请像这样清除 echo 字符:

text.setEchoChar('\0');
您甚至可以创建 Text没有 SWT.PASSWORD 的小部件style 标志并在运行时单独更改密码字符。
如果您的某些目标平台不支持像 macOS 一样更改 echo 字符,您可以重新创建密码文本字段而不使用 SWT.PASSWORD风格标志。例如:
Text oldText = text;
Composite parent = oldText.getParent();
Control[] tabList = parent.getTabList();
// clone the old password text and dispose of it
text = new Text(parent, SWT.BORDER);
text.setText(oldText.getText());
text.setLayoutData(oldText.getLayoutData());
oldText.dispose();
// insert new password text at the right position in the tab order
for(int i = 0; i < tabList.length; i++) {
if(tabList[i] == oldText) {
tabList[i] = text;
}
}
parent.setTabList(tabList);
parent.requestLayout();

关于swt - 如何动态隐藏或显示 SWT 密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41439121/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com