• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

clear JTextArea

 
puja
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone suggest a method to clear the text in the JTextArea?
Puja
 
T Pelly
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try using the method:
replaceRange(String str, int start, int end)
str = ""
start = 0
end = 'how ever many character you have'
There must be a cleaner way, but I'm not sure what it is!
 
Manfred Leonhardt
Ranch Hand
Posts: 1492
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi puja,
How about something simple like:
setText("");
According to API:

Sets the text of this TextComponent to the specified text. If the text is null or empty, has the effect of simply deleting the old text.

Regards,
Manfred.
 
Pedro Neves
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
MyTextArea.setText("") worked perfectly for me.
 
Darryl Burke
Bartender
Posts: 5148
11
Java Netbeans IDE Opera
  • Likes 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pedro Neves wrote:MyTextArea.setText("") worked perfectly for me.


Probably worked equally well for Puja, 11 years ago.
 
Pedro Neves
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darryl Burke wrote:
Pedro Neves wrote:MyTextArea.setText("") worked perfectly for me.


Probably worked equally well for Puja, 11 years ago.



AHAHA.. oh god.. what a dumb ass.. sorry i really didn't noticed on the date of the post..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic