I have an application that is sort of a networked console. It allows multiple clients to send messages to it, and displays those messages either in a console instance or in a JFrame with a JTextArea.
I ran into the problem of the JTextArea not scrolling down when new text was appended. (FYI, the JTextArea is in a JScrollPane.) Once the JTextArea contained more lines of text than could be displayed, the new text being appended wasn’t visible unless I scrolled. What I wanted was automatic scrolling. That was accomplished with one line of code:
textArea.setCaretPosition(textArea.getDocument().getLength());
0 comments ↓
There are no comments yet...Kick things off by filling out the form below.
You must log in to post a comment.