File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Blank space question" Watch "Blank space question" New topic

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:

Paul Stevens
Ranch Hand

Joined: May 17, 2001
Posts: 2823
if (textfield.getText().trim().equals("")){//do something}
I agree. Here's the link:
subject: Blank space question
It's not a secret anymore!