wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes Delete last character appended in TextArea Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Delete last character appended in TextArea" Watch "Delete last character appended in TextArea" New topic

Delete last character appended in TextArea

Jose Correa

Joined: Feb 19, 2002
Posts: 6
Hi, I'm using a non-editable TextArea and I need to delete the last character appended, I've tried using get/setCaretPosition, but the cursor in the TextArea is always located at 0.
The only input I have used for the TextArea is: textarea.append(string)
Hope someone can help..
Jason Kretzer
Ranch Hand

Joined: May 31, 2001
Posts: 280
Sorry if you have already tried this:
Have you tried to delete the last character of the last string before appending it?

Jason R. Kretzer<br />Software Engineer<br />System Administrator<br /><a href="http://alia.iwarp.com" target="_blank" rel="nofollow">http://alia.iwarp.com</a>
Roy Ben Ami
Ranch Hand

Joined: Jan 13, 2002
Posts: 732
ok. lets see, i thought of these two ways although there may be better ones:
1) if you have a TextArea (AWT) you can use the method getText() to get all the text in the TextArea as a String, and then use String methods to delete the last char and set back the text in the text area using setText(String x);
2) if its JTextArea (SWING) then you can get the document using the function getDocument(). then activate this function on the Documnet: getEndPosition() which return an object of Position. use the fucntion getOffSet to get the int offest for the documnet and then ! (finally ) append the new text at the offset position -1 .
I agree. Here's the link: http://aspose.com/file-tools
subject: Delete last character appended in TextArea
Similar Threads
Text Area..please help urgent
onKeyPress Event In Javascript
it work corectly in internet explorer,but not in firefox
Mock Question on EJB-QL
Need help in deleting last character of string.