Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Scrolling JTextArea to end of input

807599May 7 2007 — edited May 7 2007
I searched the tutorials and the Javadoc but couldn't find how to force a read-only JTextArea in a JScrollPane to keep scrolling to the end of the display when I append text.

At the moment the vertical scroll bar sits at the beginning, while appended text just disappears out of sight.

This is my code:
            progressText = new JTextArea(10, 20);
            progressText.setEditable(false);
            progressScroll = new JScrollPane(progressText, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                    JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
There must be a simple solution to this, but I can't find it!

I suspect I need to implement a DocumentListener, but don't know what to put in it.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 4 2007
Added on May 7 2007
3 comments
145 views