Search code examples
canvasjavafxrichtextfx

Scroll Position in RichTextFX


I'm using RichTextFX for a project, and want to add a Canvas to the background of the CodeArea in RichTextFX. I've done so, but I haven't been able to find a way to make it scroll with the CodeArea itself.

Is there a way to get the scroll position of the CodeArea programmatically so I can do this?


Solution

  • While I haven't found good way of scrolling in percentage, the following is my current workaround, which works, if the scroll position correlates to some character position in the text:

    int index = codeArea.getText().indexOf(textToFind);
    codeArea.moveTo(index);
    codeArea.selectRange(index, index);