Reputation: 1596
How can I move the current scroll view of a JTextArea down so that the caret appears at the top of the JTextArea? Thanks.
Upvotes: 0
Views: 1476
Reputation: 109557
You can do:
Point pt = textArea.getCaret().getMagicCaretPosition();
Rectangle rect = new Rect(pt, new Dimension(1, 10));
textArea.scrollRectToVisible(rect);
One can also use the getDocument
for a better selection.
Upvotes: 1
Reputation: 7391
Place the JTextArea inside a JScrollPane, and invoke
scrollPane.getVerticalScrollBar().setValue(value);
Upvotes: 0