Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cannot detect when text area is empty

Status
Not open for further replies.

Oxymoron

Technical User
Dec 17, 2000
168
GB
I have a text area, which extends KeyAAdapater.
so each time a character is released a KeyEvent is sent to my KeyHandler class.
What I want to do is detect when the user has deleted (by backspace or del) all th text in the text area.
at the moment I have this:
-----------------code-------------------------------
if (textArea.getText().length() == 0)
{
label.setText("No text in textArea");
}
-----------------------------------------------------
However when the user does delete all text in text1, nothing happens...

Does anyone know why this may be, and what i can do to get it to work???
Any and all suggestions are very welcome!
Thanks,
Oxy

we are all of us living in the gutter.
But some of us are looking at the stars.
 
first, are you sure...

if (textArea.getText().length() == 0)

executes at the time you want it to?

next, have you looked at the value of textArea.getText().length() ? What is the value?

Assuming the code executes when you think it does then the length of the text in textArea must not be equal to zero.

-pete
 
Maybe this is too simple (I think pete is correct to look at your events) but consider changing this

-----------------code-------------------------------
if (textArea.getText().length() == 0)
{
label.setText("No text in textArea");
}
-----------------------------------------------------
to this

-----------------code-------------------------------
if ( textArea.getText().equals("") )
{
label.setText("No text in textArea");
}
-----------------------------------------------------
Just a thought.

Javelin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top