Search code examples
javaswingjtextarea

Inserting text in JTextArea


i am developing a simple application in Java and i wanted to know if there is any way i can insert additional text(somewhere in the middle of a sentence) inside a textarea , which is not empty, at a position where the cursor is placed on the click of some component. Can someone please direct me how to go about getting it done


Solution

  • If this is a JTextArea component you can use the .append method to add text to the end of the text area, or the .insert method to insert the new text at a specific position.

    If you need to insert the text at the current caret position use the .getCaretPosition method