简体   繁体   English

启用文本字段后如何清除?

[英]How can I clear the textfield when it is enabled?

The textfield is disabled and with text. 文本字段被禁用并带有文本。

When I touch a button, the textfield will be enabled for editing. 当我触摸按钮时,将启用文本字段进行编辑。

However, I would like to textfield to be cleared when enabled. 但是,我希望启用文本字段时将其清除。

One constraint is that I can;t add any other listener to the button. 一个约束是我不能向该按钮添加任何其他侦听器。

Is there anyone can answer my question? 有没有人可以回答我的问题?

Many Thanks! 非常感谢!

Try this.. 尝试这个..

Inside the button listener that enables the textfield , after enabling statement,just add mytext.setText(""); 在启用文本字段的按钮侦听器内部 ,启用语句后,只需添加mytext.setText("");

You could attach a property listener and listen for the "enabled" event 您可以附加属性侦听器并侦听“ enabled”事件

field.addPropertyChangeListener("enabled", listener);

This doesn't require you mess around with the field at all... 这根本不需要您弄乱现场...

check here, Here is the answer of your question. 在这里检查,这是您问题的答案。 You just need some modifications... 您只需要进行一些修改...

Java JTextField with input hint 具有输入提示的Java JTextField

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM