Java jtextarea's scroll bar and line feed

Source: Internet
Author: User

Import
Java. AWT .*;
ImportJava. AWT. event .*;
ImportJavax. Swing .*;

PublicClassJtextarea2 {
 PublicStaticVoidMain (string []ARGs ){
 JframeF = newJframe ("jtextarea2 ");
 ContainerContentpane = f. getcontentpane ();
 Contentpane. setlayout (NewBorderlayout ());
  
 JpanelP1 = newJpanel ();
 P1.setlayout (NewGridlayout (1, 1 ));
 P1.setborder (borderfactory. createtitledborder ("construct textarea-use gridlayout, add scrollbar "));
  
 JtextareaT1 = newJtextarea (5, 25 );
 T1.settabsize (10 );
 T1.setfont (NewFont ("", Font. Bold, 16 ));
 T1.setlinewrap (true); // enable the line feed function
 T1.setwrapstyleword (true); // activate the word breaking Function
  
 P1.add (NewJscrollpane (T1); // place jtextarea in jscrollpane, so that you can see that the input height exceeds the height of jtextarea through the scrolling Effect
 // Text.
 Contentpane. Add (P1 );
 F. Pack ();
 F. Show ();
 F. addwindowlistener (NewWindowadapter (){
 PublicVoidWindowclosing (receivweventE ){
 System. Exit (0 );
 }
 });
 }
}

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.