类 java.awt.TextArea
java.lang.Object
|
+----java.awt.Component
|
+----java.awt.TextComponent
|
+----java.awt.TextArea
- public class TextArea
- extends TextComponent
TextArea 对象显示多行文本的区域。它可以被设置为可编辑的或只读的。
下面图象显示了一个文本区域的外观:
这个文本区域可通过如下代码创建:
new TextArea("Hello", 5, 40);
变量索引
- SCROLLBARS_BOTH
- 创建且显示水平和垂直的滚动条。
- SCROLLBARS_HORIZONTAL_ONLY
- 仅创建和显示水平滚动条。
- SCROLLBARS_NONE
- 不创建或显示该文本区域的任何滚动条。
- SCROLLBARS_VERTICAL_ONLY
- 仅创建和显示垂直滚动条。
构造子索引
- TextArea()
- 创建一个新的文本区域。
- TextArea(int, int)
- 用指定的行、列数创建一个新的文本区域。
- TextArea(String)
- 用指定文本,创建一个新的文本区域。
- TextArea(String, int, int)
- 用指定的文本和行、列数,创建一个新的文本区域。
- TextArea(String, int, int, int)
- 用指定的文本、行列数和可视的滚动条,创建一个新的文本区域。
方法索引
- addNotify()
- 创建文本区域的同级件。
- append(String)
- 向当前文本区域追加给定文本。
- appendText(String)
-
不推荐使用该方法。
- getColumns()
- 获取当前文本区域的列数。
- getMinimumSize()
- 确定当前文本区域的最小尺寸。
- getMinimumSize(int, int)
- 用指定的行、列数,确定文本区域的最小尺寸。
- getPreferredSize()
- 确定当前文本区域的最佳尺寸。
- getPreferredSize(int, int)
- 用指定的行、列数,确定文本区域的最佳尺寸。
- getRows()
- 获取文本区域的行数。
- getScrollbarVisibility()
- 获取一个枚举值,指示文本区域使用哪个滚动条。
- insert(String, int)
- 在当前文本区域内的指定位置,插入指定文本。
- insertText(String, int)
-
不推荐使用该方法。
- minimumSize()
-
不推荐使用该方法。
- minimumSize(int, int)
-
不推荐使用该方法。
- paramString()
- 返回表示当前文本区域状态的参数串。
- preferredSize()
-
不推荐使用该方法。
- preferredSize(int, int)
-
不推荐使用该方法。
- replaceRange(String, int, int)
- 用指定的置换文本,替换指定的开始和结束位置间的文本。
- replaceText(String, int, int)
-
不推荐使用该方法。
- setColumns(int)
- 设置当前文本区域的列数。
- setRows(int)
- 设置当前文本区域的行数。
变量
SCROLLBARS_BOTH
public static final int SCROLLBARS_BOTH
- 创建且显示水平和垂直的滚动条。
SCROLLBARS_VERTICAL_ONLY
public static final int SCROLLBARS_VERTICAL_ONLY
- 仅创建和显示垂直滚动条。
SCROLLBARS_HORIZONTAL_ONLY
public static final int SCROLLBARS_HORIZONTAL_ONLY
- 仅创建和显示水平滚动条。
SCROLLBARS_NONE
public static final int SCROLLBARS_NONE
- 不创建或显示该文本区域的任何滚动条。
构造子
TextArea
public TextArea()
- 创建一个新的文本区域。
此文本区域拥有垂直和水平两个滚动条。
TextArea
public TextArea(String text)
- 用指定文本,创建一个新的文本区域。
此文本区域拥有垂直和水平两个滚动条。
- 参数:
- text - 显示的文本。
TextArea
public TextArea(int rows,
int columns)
- 用指定的行、列数创建一个新的文本区域。
- 参数:
- rows - 行数
- columns - 列数
TextArea
public TextArea(String text,
int rows,
int columns)
- 用指定的文本和行、列数,创建一个新的文本区域。
此文本区域拥有垂直和水平两个滚动条。
- 参数:
- text - 显示的文本。
- rows - 行数
- columns - 列数
TextArea
public TextArea(String text,
int rows,
int columns,
int scrollbars)
- 用指定的文本、行列数和可视的滚动条,创建一个新的文本区域。
对 scrollbars 参数,类 TextArea 定义了以下几个常量:SCROLLBARS_BOTH,
SCROLLBARS_VERTICAL_ONLY,
SCROLLBARS_HORIZONTAL_ONLY,
和 SCROLLBARS_NEITHER.
- 参数:
- text - 显示的文本。
- rows - 行数
- columns - 列数
- scrollbars - 一个常量,指示文本区域中创建和显示的滚动条。
方法
addNotify
public void addNotify()
- 创建文本区域的同级件。 该同级件允许在不改变文本区域功能的情况下改变其外观。
- 覆盖:
- 类 Component 中的
addNotify
insert
public synchronized void insert(String str,
int pos)
- 在当前文本区域内的指定位置,插入指定文本。
- 参数:
- str - 待插入的文本。
- pos - 文本的插入位置
- 参见:
- setText, replaceRange, append
insertText
public void insertText(String str,
int pos)
- 注释:不推荐使用 insertText() 方法。
同 JDK 1.1 版类似, 用
insert(String, int) 方法替换。
append
public synchronized void append(String str)
- 向当前文本区域追加给定文本。
- 参数:
- str - 待追加的文本。
- 参见:
- insert
appendText
public void appendText(String str)
- 注释:不推荐使用 appendText() 方法。
同 JDK 1.1 版一样, 用
append(String) 方法替换。
replaceRange
public synchronized void replaceRange(String str,
int start,
int end)
- 用指定的置换文本,替换指定的开始和结束位置间的文本。
- 参数:
- str - 用作替换的文本。
- start - 开始位置。
- end - 结束位置。
- 参见:
- insert
replaceText
public void replaceText(String str,
int start,
int end)
- 注释:不推荐使用 replaceText() 方法。
同 JDK 1.1 版类似, 用
replaceRange(String, int, int)
方法替换。
getRows
public int getRows()
- 获取文本区域的行数。
- 返回值:
- 文本区域的行数。
- 参见:
- setRows, getColumns
setRows
public void setRows(int rows)
- 设置当前文本区域的行数。
- 参数:
- rows - 行数
- 抛出:
IllegalArgumentException
- 如果给定的
rows 值小于零。
- 参见:
- getRows, setColumns
getColumns
public int getColumns()
- 获取当前文本区域的列数。
- 返回值:
- 文本区域的列数。
- 参见:
- setColumns, getRows
setColumns
public void setColumns(int columns)
- 设置当前文本区域的列数。
- 参数:
- columns - 列数
- 抛出:
IllegalArgumentException
- 如果给定的
columns 值小于零。
- 参见:
- getColumns, setRows
getScrollbarVisibility
public int getScrollbarVisibility()
- 获取一个枚举值,指示文本区域使用哪个滚动条。
为指定可用的滚动条,类 TextArea 定义了四个整型常量。另外 TextArea 有一个构造子,赋予应用程序对滚动条的处理权限。
- 返回值:
- 一个整数,指示使用的是哪个滚动条。
- 参见:
- SCROLLBARS_BOTH, SCROLLBARS_VERTICAL_ONLY, SCROLLBARS_HORIZONTAL_ONLY, SCROLLBARS_NEITHER, TextArea
getPreferredSize
public Dimension getPreferredSize(int rows,
int columns)
- 用指定的行、列数,确定文本区域的最佳尺寸。
- 参数:
- rows - 行数
- cols - 列数
- 返回值:
- 用指定的行、列数显示文本区域的最佳尺寸。
- 参见:
- getPreferredSize
preferredSize
public synchronized Dimension preferredSize(int rows,
int columns)
- 注释:不推荐使用 preferredSize() 方法。
同 JDK 1.1 版类似, 用
getPreferredSize(int, int) 方法替换。
getPreferredSize
public Dimension getPreferredSize()
- 确定当前文本区域的最佳尺寸。
- 返回值:
- 当前文本区域所需的最佳尺寸。
- 覆盖:
- 类 Component 中的
getPreferredSize
- 参见:
- getPreferredSize
preferredSize
public synchronized Dimension preferredSize()
- 注释:不推荐使用 preferredSize()。
如同 JDK 1.1 版,用
getPreferredSize() 替换。
- 覆盖:
- 类 Component
中的
preferredSize
getMinimumSize
public Dimension getMinimumSize(int rows,
int columns)
- 用指定的行、列数,确定文本区域的最小尺寸。
- 参数:
- rows - 行数
- cols - 列数
- 返回值:
- 用指定的行、列数显示文本区域所需的最小尺寸。
- 参见:
- getMinimumSize
minimumSize
public synchronized Dimension minimumSize(int rows,
int columns)
- 注释:不推荐使用 minimumSize()。
同 JDK 1.1 版类似, 用
getMiniSize(int, int) 方法替换。
getMinimumSize
public Dimension getMinimumSize()
- 确定当前文本区域的最小尺寸。
- 返回值:
- 当前文本区域所需的最佳尺寸。
- 覆盖:
- 类 Component 中的
getMinimumSize
- 参见:
- getPreferredSize
minimumSize
public synchronized Dimension minimumSize()
- 注释:不推荐使用 minimumSize()。
如同 JDK 1.1 版,用
getMinimumSize() 替换。
- 覆盖:
- 类
Component
中的
minimumSize
paramString
protected String paramString()
- 返回表示当前文本区域状态的参数串。 该字符串对调试有用。
- 返回值:
- 表示当前文本区域的参数串。
- 覆盖:
- 类 TextComponent 中的 paramString