• 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: 925
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
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!