• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Delete last character appended in TextArea

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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..
Thanks
 
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry if you have already tried this:
Have you tried to delete the last character of the last string before appending it?
HTH,
 
Ranch Hand
Posts: 732
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 .
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic