Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Blank space question

 
Peter Phung
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Matt Siegel
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try trimming the String after you call the getText() method, like this:

HTH,
Matt
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or
if (textfield.getText().trim().equals("")){//do something}
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic