William LAM
William LAM

Reputation: 455

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!

Upvotes: 0

Views: 274

Answers (3)

MadProgrammer
MadProgrammer

Reputation: 347204

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...

Upvotes: 1

Himanshu Soni
Himanshu Soni

Reputation: 461

check here, Here is the answer of your question. You just need some modifications...

Java JTextField with input hint

Upvotes: 0

Kumar Vivek Mitra
Kumar Vivek Mitra

Reputation: 33534

Try this..

Inside the button listener that enables the textfield, after enabling statement,just add mytext.setText("");

Upvotes: 2

Related Questions