Try adding this after setting the cursor position:
textAreaToScroll.getElement().setScrollTop(textAreaToScroll.getElement().getScrollHeight());
This will scroll the item to the bottom.
EDIT:
There is no easy way to do this to scroll to any cursor position (as far as I know). I don’t think there is any way to ask the browser on which the cursor is on. I just got an idea of something that might work (I didn't actually test it) to guess a rough estimate of how much time is scrolling.
int cursorPos = textAreaToScroll.getCursorPos(); long offsetRatio = cursorPos / textAreaToScroll.getText().length();
This can scroll approximately the desired distance. Please note: this assumes that each line is filled with approximately the same amount, since it uses the cursor position divided by the length of the text, and not the number of lines (which are difficult to calculate). Manual newline characters will distort this estimate, and proportional fonts will also make it less accurate.
You will probably need to adjust the ratio so that it scrolls too short and not too far, since the cursor will still be visible if it is slightly below the top of the text area.
As I said, I did not actually test this, I may have turned the logic and other subtle errors.
source share