wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Blank space question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Blank space question" Watch "Blank space question" New topic
Author

Blank space question

Peter Phung
Ranch Hand

Joined: Dec 06, 2001
Posts: 138
How can i tell if a textfield is blank?
i've tried using

it works ok if no key has been pressed, but if the space bar has been pressed the length would be greater than 1 but the text field would still be blank.
Any suggestions would be appreciated


Pete<br />"Reality is an illusion <br />brought on by a lack of <br />drink, drugs and smut"
Matt Siegel
Ranch Hand

Joined: Jul 18, 2000
Posts: 55
Try trimming the String after you call the getText() method, like this:

HTH,
Matt
Paul Stevens
Ranch Hand

Joined: May 17, 2001
Posts: 2823
Or
if (textfield.getText().trim().equals("")){//do something}
}
 
 
subject: Blank space question