简体   繁体   中英

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("");

You could attach a property listener and listen for the "enabled" event

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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