TextArea
TextAreaクラスは
Componentの直接のサブクラスではなく、
TextComponentクラス
のサブクラスです。
java.awtパッケージに含まれます。
TextAreaクラスは、
テキストを入力するためのアイテムの
機能を提供します。
TextAreaは複数行にわたるテキストの入力処理に用いられます。
1行のみのテキストを取り扱うためには、
TextFieldクラス
が用意されています。
TextAreaクラスには、
スクロールバーの有無を指定するための
publicで static かつ finalなフィールドが4個定義されています。
- public static final int SCROLLBARS_BOTH
- public static final int SCROLLBARS_VERTICAL_ONLY
- public static final int SCROLLBARS_HORIZONTAL_ONLY
- public static final int SCROLLBARS_NONE
この他にオブジェクトのサイズや色などの基本的な性質は
Componentクラスから、
テキストの内容の情報は TextComponentクラスから継承し、
内部に記憶しています。
TextAreaクラスのメソッド
TextAreaクラスには、
5個のコンストラクタと20個のpublic なメソッドが用意されています。
また、テキストを取り扱うための基本的なメソッドは、
TextComponentクラス
の中で定義されています。
コンストラクタ
- public TextArea()
- public TextArea(String text)
- public TextArea(int rows, int columns)
- public TextArea(String text, int rows, int columns)
- public TextArea(String text, int rows, int columns, int scrollbars)
textはアイテムの初期設定の文字列です。
columnsはアイテムに表示可能な桁数、rowsは表示可能なテキストの行数です。
scrollbars は上記のフィールドのいずれかの値を用いて、スクロールバーの
有無を指定します。
メッソド
- public int getRows()
- public void setRows(int rows)
- public int getColumns()
- public void setColumns(int columns)
- public int getScrollbarVisibility()
- public Dimension getPreferredSize(int rows, int columns)
- public Dimension preferredSize(int rows, int columns)
- public Dimension getPreferredSize()
- public Dimension preferredSize()
- public Dimension getMinimumSize(int rows, int columns)
- public Dimension minimumSize(int rows, int columns)
- public Dimension getMinimumSize()
- public Dimension minimumSize()
- public synchronized void append(String str)
- public void appendText(String str)
- public synchronized void insert(String str, int pos)
- public void insertText(String str, int pos)
- public synchronized void replaceRange(String str, int start, int end)
- public void replaceText(String str, int start, int end)
- public void addNotify()
getRows()は表示可能な行数を返し、
setRows()は表示可能な行数を設定します。
getColumns()は表示可能な桁数を返し、
setColumns()は表示可能な桁数を設定します。
getScrollbarVisibility()はスクロールバーが表示されているかどうかを、
上記のフィールドの値のいずれかで返します。
getPreferredSize(),preferredSize()は指定された表示可能な行数、桁数に対応した
画面上での実際のサイズを返します。表示可能な行数、桁数の指定を省略した場合には
現在の表示可能な行数、桁数に対応するサイズを返します。
JDK1.1では getPreferredSize() を使用することが推奨されています。
getMinimumSize(),minimumSize()は指定された表示可能な行数、桁数に対応した
画面上での最小のサイズを返します。表示可能な行数、桁数の指定を省略した場合には
現在の表示可能な行数、桁数に対応する最小のサイズを返します。
JDK1.1では getMinimumSize() を使用することが推奨されています。
append(),appendText()はテキストの末尾に文字列の内容を追加します。
JDK1.1では add()を使用することが推奨されています。
insert(),insertText()はテキストの指定された場所に文字列の内容を挿入します。
JDK1.1では insert()を使用することが推奨されています。
replaceRange(),replaceText()は、
指定された範囲のテキストの部分を新しい内容に置き換えます。
JDK1.1では replaceRange()を使用することが推奨されています。
addNotify()は独自のデザインを利用する場合に、その登録のために呼び出します。