Actually I know only about getText and setText for manipulating the text in a RSyntaxTestArea.
But it would be nice, to change only one line/row.
The means to do this comes from the methods inherited from JTextArea
- Code: Select all
public int getLineStartOffset(int line)
public int getLineEndOffset(int line)
public void replaceRange(String str, int start, int end)
public void insert(String str, int pos)
You can simply get the starting and ending offsets of the line to change, and modify it as appropriate with replaceRange() and/or insert().
Additional it would be nice, if I change the line (with [Enter], the Arrow-Keys or so on),that I can then with a function/method reorganize/restructure/reformat the line before.
You can do this by adding a CaretListener
to the editor. When the caret moves, you can use the getLineOfOffset(int offs) method to get the line the caret is on, and the methods above to then modify it as you wish. Of course, if you want to modify the *previous* line, you'll have to store the *previous* caret position in your CaretListener. Then, each time the caret position changes, get the line of the *previous* caret position, and operate on that line, and then update your "previous caret position" field. That way you're always modifying the line where the caret was
, not where it's just moved to.