• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTextArea query..

 
kieran pattni
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi..if i a click button to get text from JTextArea and its blank JTextArea ..shouldnt i get null from getText();or NullPointerException...basically what i want to do is if null //do something ...if text in texArea // do something else....using ActionListener which might be wrong Listener to use...thank you
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, you'll always get an empty string. So what you need to check is:

 
Brian Cole
Author
Ranch Hand
Posts: 912
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by kieran pattni:
if i a click button to get text from JTextArea and its blank JTextArea ..shouldnt i get null from getText();or NullPointerException...


No. You should get an empty String. You can test via:

yourTextArea.getText().equals("")

yourTextArea.getText().length() == 0

yourTextArea.getDocument().getLength() == 0
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic