JavaFX TextArea: How to insert text at the cursor/caret position

JavaFX TextArea FAQ: How do I insert a string/text into a TextArea at the cursor/caret position?

Solution: First get the position of the cursor/caret in the TextArea, then insert your new text at that position:

int caretPosition = notesTextArea.getCaretPosition;
notesTextArea.insertText(caretPosition, "My new text");

You can also append text to a TextArea, but to insert text at the caret position, I just used that code and it seems to work well.

“Treat every moment as your last.
It is not preparation for something else.”
~ Shunryu Suzuki