(1) After JTextArea inserts the last message, use SelectAll () to force the cursor to move to the end of the JTextArea, which enables the scroll bar to scroll automatically. (The way in which Aviva is used)
(2) After JTextArea inserts the last message, use (JTextArea) recvarea.setcaretposition (Recvarea.gettext (). Length ()), move the cursor to the end, and implement the scroll bar's automatic scrolling.
(3) After JTextArea loaded the automatic scroll bar jscroll, add JTextArea to Jscrolpanel viewport: (There are bugs that make the image a little bit blinking)
Recvscrollpane.getviewport (). Add (Recvarea, NULL);
Then, after JTextArea inserts the last new message, reset the scroll bar's viewport to the bottom position:
int height = 20;
Point P = new Point ();
P.setlocation (0, Recvarea.getlinecount () * height);
Recvscrollpane.getviewport (). Setviewposition (P);