Moving to a given line in the document

Questions on using RSyntaxTextArea should go here.

Moderator: robert

Moving to a given line in the document

Postby majenko » Wed Aug 20, 2014 9:41 am

More a question of procedure really, as in "how do I"...

I have this method:
Code: Select all
    public void gotoLine(final int line) {
        try {
            textArea.setCaretPosition(textArea.getLineStartOffset(line));
        } catch(BadLocationException e) {
        }
    }

and it works really nicely. Give it a line, and it scrolls to the that line in the document.

However, if the target is further down the document it leaves you with the caret at the bottom of the text area. If the target is higher up, it leaves you with the caret at the top of the text area. What I'd really like is for it to leave you with the target line centred in the middle of the text area.

I guess this is going to mean manipulating the RTSP in some way, but my Java skills don't stretch that far yet ;)

An ideal solution from my perspective would be a scrollPane.centerOnCaret() method - maybe enhancing it with an optional parameter to say where to place the line - top, bottom or middle - but that would mean you doing the work not me ;)

So what ideas could you suggest for achieving this desired effect?
majenko
 
Posts: 16
Joined: Sun Jul 14, 2013 11:01 am

Return to Help

Who is online

Users browsing this forum: No registered users and 1 guest

cron