Java Swing TextArea scroll bar and get focus

Source: Internet
Author: User

JTextArea text=new JTextArea () Text.setlinewrap (TRUE);//Set the line wrap, then do not need to set the horizontal scroll bar jscrollpane scroll=new JScrollPane ( text);//Set horizontal and vertical scroll bars to appear automatically scroll.sethorizontalscrollbarpolicy (jscrollpane.horizontal_scrollbar_as_needed) respectively; Scroll.setverticalscrollbarpolicy (jscrollpane.vertical_scrollbar_as_needed); setting horizontal and vertical scrollbars, respectively, always appears Scroll.sethorizontalscrollbarpolicy (jscrollpane.horizontal_scrollbar_always); Scroll.setverticalscrollbarpolicy (jscrollpane.vertical_scrollbar_always); setting horizontal and vertical scrollbars, respectively, always hides Scroll.sethorizontalscrollbarpolicy (jscrollpane.horizontal_scrollbar_never); Scroll.setverticalscrollbarpolicy (Jscrollpane.vertical_scrollbar_never); Container Container=mynote.getcontentpane (); Container.add (Scroll,borderlayout.east); Note: Add the scrollbar scoll to the form without adding the scoll textarea, otherwise the myframe.add (scroll) will not be displayed;




Get textarea last last line focus
JTextArea textarea = new JTextArea ();
Textarea.append ("DFASFSADFASFD");
Textarea.setcaretposition (Textarea.gettext (). Length ());

Java Swing TextArea scroll bar and get focus

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.