【Swing/文本組件】定義自動換行的文本域


  • 文本域組件:Swing中任何一個文本域(JTextArea)都是JTestArea類型的對象。常用的構造方法如下
    • public JTextArea()
    • public JTextArea(String text)
    • public JTextArea( int rows,int columns)
    • public JTextArea(Document doc)
  • 定義自動換行的文本域
     1 /**
     2  * 
     3  */
     4 package 常用窗體;
     5 
     6 import java.awt.Container;
     7 
     8 import javax.swing.JFrame;
     9 import javax.swing.JTextArea;
    10 import javax.swing.WindowConstants;
    11 
    12 /**
    13  * @author 粵晨下午9:29:54
    14  *
    15  */
    16 public class JTextAreaTest  extends JFrame{
    17     public JTextAreaTest() {
    18         
    19     
    20     Container c=getContentPane();
    21     JTextArea jt=new JTextArea("文本域",6,6);
    22     jt.setLineWrap(true);
    23     c.add(jt);
    24     setVisible(true);
    25     setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    26     
    27     }
    28     /**
    29      * @param args
    30      */
    31     public static void main(String[] args) {
    32         // TODO Auto-generated method stub
    33 
    34         new JTextAreaTest();
    35     }
    36 
    37 }
    View Code

     


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM