Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making a JScrollPane automatically scroll all the way down

Tags:

I am trying to implement a JScrollPane with a JTextArea. The JTextArea is being appended to, and I want the JScrollPane to keep scrolling down as more text is added. How can this be achieved?

like image 370
Krigath Avatar asked Mar 20 '10 15:03

Krigath


People also ask

How do I make Div scroll automatically?

Set the overflow-x:hidden; and overflow-y:auto; that will automatically hide the horizontal scroll bar and present only vertical scrollbar. Here the scroll div will be vertically scrollable.

How do I make my JScrollPane scroll faster?

Just use the reference to your JScrollPane object, get the vertical scroll bar from it using getVerticalScrollBar , and then call setUnitIncrement on it, like this: myJScrollPane. getVerticalScrollBar().

What is the difference between a scrollbar and a JScrollPane?

A JSrollPane is used to make a scrollable view of a component. A scroll pane is an object of the JScrollPane class which extends JComponent class. When screen size is limited, we use a scroll pane to display a large component or a component whose size can change dynamically.


1 Answers

For (what I think is) a simpler answer check out: Text Area Scrolling.

Prior to JDK5, you would have to manually change the caret's position after each append. You can now give this behaviour as a default like this :

 JTextArea textArea = new JTextArea();  DefaultCaret caret = (DefaultCaret)textArea.getCaret();  caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE); 

The advantage of this is that you don't need to use this snippet more than once in your code!

like image 77
camickr Avatar answered Sep 19 '22 20:09

camickr