swingコンポーネント->JTextArea

テキストが複数行入力可能な領域です。表示や編集することができます。


コンストラクタ(抜粋)
JTextArea()
 JTextAreaオプジェクトを生成します。
JTextArea( int rows,int cols)
 行数rows、列数colsを指定してJTextAreaオブジェクトを生成します。
メソッド(抜粋)
void append(String str)
 文字列strを追加します。
void insert(String str,int pos)
 文字列strをposの位置に挿入します。
void replaceRange(String str,int start,int end)
 startからendまでのテキストを文字列strに置き換えします。

クリック

 
JTextAreaSample.java
import java.awt.*;  
import java.awt.event.*;  
import javax.swing.*;  
public class JTextAreaSample extends JFrame {  
   Container contentPane;  
    JTextArea txtArea = new JTextArea("文字を入力できます。"); ← @インスタンス生成
  public JTextAreaSample() {  
     super(JTextAreaSample);  
     addWindowAdapter(new WindowListener() {  
       public void windowClosing(WindowEvent e) {  
          System.exit(0);  
       }  
     });  
     contentPane = getContentPane();  
     contentPane.setLayout(new BorderLayout());  
     contentPane.add(BorderLayout.CENTER,txtArea);  
     setSize(300,200);  
     setVisible(true);  
   }  
  }  
  public static void main(String[] args) {  
    JTextAreaSample myClass = new JTextAreaSample();  
    }  
}  
@JTextAreaのインスタンスを生成
 インスタンスを生成しています。
※マウスの範囲選択や、ctrl+cでのコピー、ctrl+vでの貼り付けはできます。
もどる