Martin
Martin

Reputation: 777

jtextarea scrolling

I'm using jtextarea and it is filled dynamically during execution of my application(like logs).I want remove autoscrolling of vertical scrollbar, I mean text is adding in field and caret position isn't changing(it changes only if I dragged it manually). How can I do this? I tried scrollPane.getHorizontalScrollBar().setAutoscrolls(false) but this didn't help.

Upvotes: 1

Views: 1052

Answers (2)

mort
mort

Reputation: 13588

If I understand your question correctly, you could use something like this:

myTextArea.setCaretPosition(myTextArea.getDocument().getLength() - 1);

Upvotes: 0

Aaron Digulla
Aaron Digulla

Reputation: 328556

By itself, the text area doesn't scroll; you must have something in your code to make it happen.

The usual approach is to set the caret at the end of the document (plus caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE); when you're on Java 5; see Text Area Scrolling)

To stop the scrolling, you must find the code in your app and turn it off.

setAutoscrolls() has no effect in this case because it's only used when you drag select text and the mouse gets outside of the component plus the purpose of this property is something else (if true, synthetic mouse events will be generated as long as the mouse is outside the component).

Upvotes: 2

Related Questions