Jtextarea+jscrollpane scroll bar automatically at the bottom (turn)

Source: Internet
Author: User

(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);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.