- java.lang.Object
-
- java.awt.Component
-
- java.awt.TextComponent
-
- java.awt.TextArea
-
- 实现的所有接口
-
ImageObserver,MenuContainer,Serializable,Accessible
public class TextArea extends TextComponent
TextArea对象是显示文本的多行区域。 它可以设置为允许编辑或只读。下图显示了文本区域的外观:

可以通过以下代码行创建此文本区域:
new TextArea("Hello", 5, 40);
- 从以下版本开始:
- 1.0
- 另请参见:
- Serialized Form
-
-
嵌套类汇总
嵌套类 变量和类型 类 描述 protected classTextArea.AccessibleAWTTextArea此类实现TextArea类的可访问性支持。-
嵌套类/接口声明在类 java.awt.TextComponent
TextComponent.AccessibleAWTTextComponent
-
-
字段汇总
字段 变量和类型 字段 描述 static intSCROLLBARS_BOTH创建并显示垂直和水平滚动条。static intSCROLLBARS_HORIZONTAL_ONLY仅创建和显示水平滚动条。static intSCROLLBARS_NONE不要为文本区域创建或显示任何滚动条。static intSCROLLBARS_VERTICAL_ONLY仅创建和显示垂直滚动条。-
声明的属性在类 java.awt.TextComponent
textListener
-
声明的属性在类 java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
-
Fields declared in interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
-
-
构造方法摘要
构造方法 构造器 描述 TextArea()构造一个新的文本区域,将空字符串作为文本。TextArea(int rows, int columns)构造具有指定行数和列数的新文本区域,将空字符串构造为文本。TextArea(String text)使用指定的文本构造一个新的文本区域。TextArea(String text, int rows, int columns)使用指定的文本构造一个新的文本区域,并使用指定的行数和列数。TextArea(String text, int rows, int columns, int scrollbars)构造具有指定文本的新文本区域,并指定行,列和滚动条可见性。
-
方法摘要
所有方法 实例方法 具体的方法 弃用的方法 变量和类型 方法 描述 voidaddNotify()创建TextArea的同行。voidappend(String str)将给定文本追加到文本区域的当前文本。voidappendText(String str)已过时。截至JDK 1.1版,由append(String)取代。AccessibleContextgetAccessibleContext()返回与AccessibleContext相关联的TextArea。intgetColumns()返回此文本区域中的列数。DimensiongetMinimumSize()确定此文本区域的最小大小。DimensiongetMinimumSize(int rows, int columns)确定具有指定行数和列数的文本区域的最小大小。DimensiongetPreferredSize()确定此文本区域的首选大小。DimensiongetPreferredSize(int rows, int columns)确定具有指定行数和列数的文本区域的首选大小。intgetRows()返回文本区域中的行数。intgetScrollbarVisibility()返回一个枚举值,指示文本区域使用的滚动条。voidinsert(String str, int pos)将指定文本插入此文本区域中的指定位置。voidinsertText(String str, int pos)已过时。截至JDK 1.1版,由insert(String, int)取代。DimensionminimumSize()已过时。截至JDK 1.1版,由getMinimumSize()取代。DimensionminimumSize(int rows, int columns)已过时。截至JDK 1.1版,取而代之的是getMinimumSize(int, int)。protected StringparamString()返回表示此TextArea的状态的字符串。DimensionpreferredSize()已过时。截至JDK 1.1版,由getPreferredSize()取代。DimensionpreferredSize(int rows, int columns)已过时。截至JDK 1.1版,由getPreferredSize(int, int)取代。voidreplaceRange(String str, int start, int end)用指定的替换文本替换指示的开始和结束位置之间的文本。voidreplaceText(String str, int start, int end)已过时。截至JDK 1.1版,由replaceRange(String, int, int)取代。voidsetColumns(int columns)设置此文本区域的列数。voidsetRows(int rows)设置此文本区域的行数。-
声明方法的类 java.awt.TextComponent
addTextListener, enableInputMethods, getBackground, getCaretPosition, getListeners, getSelectedText, getSelectionEnd, getSelectionStart, getText, getTextListeners, isEditable, processEvent, processTextEvent, removeNotify, removeTextListener, select, selectAll, setBackground, setCaretPosition, setEditable, setSelectionEnd, setSelectionStart, setText
-
声明方法的类 java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAlignmentX, getAlignmentY, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paint, paintAll, postEvent, prepareImage, prepareImage, print, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, revalidate, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setMixingCutoutShape, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, update, validate
-
-
-
-
字段详细信息
-
SCROLLBARS_BOTH
public static final int SCROLLBARS_BOTH
创建并显示垂直和水平滚动条。- 从以下版本开始:
- 1.1
- 另请参见:
- 常数字段值
-
SCROLLBARS_VERTICAL_ONLY
public static final int SCROLLBARS_VERTICAL_ONLY
仅创建和显示垂直滚动条。- 从以下版本开始:
- 1.1
- 另请参见:
- 常数字段值
-
SCROLLBARS_HORIZONTAL_ONLY
public static final int SCROLLBARS_HORIZONTAL_ONLY
仅创建和显示水平滚动条。- 从以下版本开始:
- 1.1
- 另请参见:
- 常数字段值
-
SCROLLBARS_NONE
public static final int SCROLLBARS_NONE
不要为文本区域创建或显示任何滚动条。- 从以下版本开始:
- 1.1
- 另请参见:
- 常数字段值
-
-
构造方法详细信息
-
TextArea
public TextArea() throws HeadlessException构造一个新的文本区域,将空字符串作为文本。 滚动条可见性等于SCROLLBARS_BOTH创建此文本区域,因此对于此文本区域,垂直和水平滚动条都可见。- 异常
-
HeadlessException- 如果GraphicsEnvironment.isHeadless返回true - 另请参见:
-
GraphicsEnvironment.isHeadless()
-
TextArea
public TextArea(String text) throws HeadlessException
使用指定的文本构造一个新的文本区域。 滚动条可见性等于SCROLLBARS_BOTH创建此文本区域,因此此文本区域将显示垂直和水平滚动条。- 参数
-
text- 要显示的文本; 如果text是null,将显示空字符串"" - 异常
-
HeadlessException- 如果GraphicsEnvironment.isHeadless返回true - 另请参见:
-
GraphicsEnvironment.isHeadless()
-
TextArea
public TextArea(int rows, int columns) throws HeadlessException构造具有指定行数和列数的新文本区域,将空字符串构造为文本。 列是与平台相关的近似平均字符宽度。 创建的文本区域的滚动条可见性等于SCROLLBARS_BOTH,因此对于此文本区域,将显示垂直和水平滚动条。- 参数
-
rows- 行数 -
columns- 列数 - 异常
-
HeadlessException- 如果GraphicsEnvironment.isHeadless返回true - 另请参见:
-
GraphicsEnvironment.isHeadless()
-
TextArea
public TextArea(String text, int rows, int columns) throws HeadlessException
使用指定的文本构造一个新的文本区域,并使用指定的行数和列数。 列是与平台相关的近似平均字符宽度。 创建的文本区域的滚动条可见性等于SCROLLBARS_BOTH,因此对于此文本区域,垂直和水平滚动条都可见。- 参数
-
text- 要显示的文本; 如果text是null,将显示空字符串"" -
rows- 行数 -
columns- 列数 - 异常
-
HeadlessException- 如果GraphicsEnvironment.isHeadless返回true - 另请参见:
-
GraphicsEnvironment.isHeadless()
-
TextArea
public TextArea(String text, int rows, int columns, int scrollbars) throws HeadlessException
构造具有指定文本的新文本区域,并指定行,列和滚动条可见性。 所有TextArea构造函数都TextArea这一个。TextArea类定义了几个可以作为scrollbars参数的值提供的scrollbars:-
SCROLLBARS_BOTH, -
SCROLLBARS_VERTICAL_ONLY, -
SCROLLBARS_HORIZONTAL_ONLY, -
SCROLLBARS_NONE。
scrollbars参数的任何其他值都无效,并且将导致创建此文本区域时滚动条可见性等于默认值SCROLLBARS_BOTH。- 参数
-
text- 要显示的文本; 如果text是null,将显示空字符串"" -
rows- 行数; 如果rows小于0,rows设置为0 -
columns- 列数; 如果columns小于0,columns设置为0 -
scrollbars- 一个常量,用于确定创建哪些滚动条以查看文本区域 - 异常
-
HeadlessException- 如果GraphicsEnvironment.isHeadless返回true - 从以下版本开始:
- 1.1
- 另请参见:
-
GraphicsEnvironment.isHeadless()
-
-
-
方法详细信息
-
addNotify
public void addNotify()
创建TextArea的同行。 对等体允许我们修改TextArea的外观而不改变其任何功能。- 重写:
-
addNotify在类TextComponent - 另请参见:
-
TextComponent.removeNotify()
-
insert
public void insert(String str, int pos)
将指定文本插入此文本区域中的指定位置。请注意,传递
null或不一致的参数无效,将导致未指定的行为。- 参数
-
str- 要插入的非null文本 -
pos- 要插入的位置 - 从以下版本开始:
- 1.1
- 另请参见:
-
TextComponent.setText(java.lang.String),replaceRange(java.lang.String, int, int),append(java.lang.String)
-
insertText
@Deprecated public void insertText(String str, int pos)
Deprecated.As of JDK version 1.1, replaced byinsert(String, int).将指定文本插入此文本区域中的指定位置。- 参数
-
str- 要插入的非null文本 -
pos- 要插入的位置
-
append
public void append(String str)
将给定文本追加到文本区域的当前文本。请注意,传递
null或不一致的参数无效,将导致未指定的行为。- 参数
-
str- 要追加的非null文本 - 从以下版本开始:
- 1.1
- 另请参见:
-
insert(java.lang.String, int)
-
appendText
@Deprecated public void appendText(String str)
Deprecated.As of JDK version 1.1, replaced byappend(String).将给定文本追加到文本区域的当前文本。- 参数
-
str- 要追加的文本
-
replaceRange
public void replaceRange(String str, int start, int end)
用指定的替换文本替换指示的开始和结束位置之间的文本。 最终位置的文本不会被替换。 将替换起始位置处的文本(除非起始位置与结束位置相同)。 文本位置从零开始。 插入的子字符串的长度可以与它替换的文本的长度不同。请注意,传递
null或不一致的参数无效,将导致未指定的行为。- 参数
-
str- 用作替换的非null文本 -
start- 起始位置 -
end- 结束位置 - 从以下版本开始:
- 1.1
- 另请参见:
-
insert(java.lang.String, int)
-
replaceText
@Deprecated public void replaceText(String str, int start, int end)
Deprecated.As of JDK version 1.1, replaced byreplaceRange(String, int, int).用指定的替换文本替换指示的开始和结束位置之间的一系列字符(不会替换结束位置的文本)。- 参数
-
str- 非null文本用作替换 -
start- 起始位置 -
end- 结束位置
-
getRows
public int getRows()
返回文本区域中的行数。- 结果
- 文本区域中的行数
- 从以下版本开始:
- 1.0
- 另请参见:
-
setRows(int),getColumns()
-
setRows
public void setRows(int rows)
设置此文本区域的行数。- 参数
-
rows- 行数 - 异常
-
IllegalArgumentException- 如果为rows提供的值小于0 - 从以下版本开始:
- 1.1
- 另请参见:
-
getRows(),setColumns(int)
-
getColumns
public int getColumns()
返回此文本区域中的列数。- 结果
- 文本区域中的列数
- 另请参见:
-
setColumns(int),getRows()
-
setColumns
public void setColumns(int columns)
设置此文本区域的列数。- 参数
-
columns- 列数 - 异常
-
IllegalArgumentException- 如果为columns提供的值小于0 - 从以下版本开始:
- 1.1
- 另请参见:
-
getColumns(),setRows(int)
-
getScrollbarVisibility
public int getScrollbarVisibility()
返回一个枚举值,指示文本区域使用的滚动条。TextArea类定义了四个整数常量,用于指定哪些滚动条可用。TextArea有一个构造函数,使应用程序可以自由选择滚动条。- 结果
- 一个整数,指示使用哪个滚动条
- 从以下版本开始:
- 1.1
- 另请参见:
-
SCROLLBARS_BOTH,SCROLLBARS_VERTICAL_ONLY,SCROLLBARS_HORIZONTAL_ONLY,SCROLLBARS_NONE,TextArea(java.lang.String, int, int, int)
-
getPreferredSize
public Dimension getPreferredSize(int rows, int columns)
确定具有指定行数和列数的文本区域的首选大小。- 参数
-
rows- 行数 -
columns- 列数 - 结果
- 显示具有指定行数和列数的文本区域所需的首选尺寸
- 从以下版本开始:
- 1.1
- 另请参见:
-
Component.getPreferredSize()
-
preferredSize
@Deprecated public Dimension preferredSize(int rows, int columns)
Deprecated.As of JDK version 1.1, replaced bygetPreferredSize(int, int).确定具有指定行数和列数的文本区域的首选大小。- 参数
-
rows- 行数 -
columns- 列数 - 结果
- 文本区域所需的首选尺寸
-
getPreferredSize
public Dimension getPreferredSize()
确定此文本区域的首选大小。- 重写:
-
getPreferredSize在类Component - 结果
- 此文本区域所需的首选尺寸
- 从以下版本开始:
- 1.1
- 另请参见:
-
Component.getPreferredSize()
-
preferredSize
@Deprecated public Dimension preferredSize()
Deprecated.As of JDK version 1.1, replaced bygetPreferredSize().复制自类的说明:Component返回组件的首选大小。- 重写:
-
preferredSize在类Component - 结果
- 组件的首选大小
-
getMinimumSize
public Dimension getMinimumSize(int rows, int columns)
确定具有指定行数和列数的文本区域的最小大小。- 参数
-
rows- 行数 -
columns- 列数 - 结果
- 显示具有指定行数和列数的文本区域所需的最小尺寸
- 从以下版本开始:
- 1.1
- 另请参见:
-
Component.getMinimumSize()
-
minimumSize
@Deprecated public Dimension minimumSize(int rows, int columns)
Deprecated.As of JDK version 1.1, replaced bygetMinimumSize(int, int).确定具有指定行数和列数的文本区域的最小大小。- 参数
-
rows- 行数 -
columns- 列数 - 结果
- 文本区域的最小大小
-
getMinimumSize
public Dimension getMinimumSize()
确定此文本区域的最小大小。- 重写:
-
getMinimumSize在类Component - 结果
- 此文本区域所需的首选尺寸
- 从以下版本开始:
- 1.1
- 另请参见:
-
Component.getPreferredSize()
-
minimumSize
@Deprecated public Dimension minimumSize()
Deprecated.As of JDK version 1.1, replaced bygetMinimumSize().从类复制的说明:Component返回此组件的最小大小。- 重写:
-
minimumSize在类Component - 结果
- 此组件的最小大小
-
paramString
protected String paramString()
返回表示此TextArea的状态的字符串。 此方法仅用于调试目的,返回字符串的内容和格式可能因实现而异。 返回的字符串可能为空,但可能不是null。- 重写:
-
paramString在类TextComponent - 结果
- 此文本区域的参数字符串
-
getAccessibleContext
public AccessibleContext getAccessibleContext()
返回与AccessibleContext相关联的TextArea。 对于文本区,AccessibleContext需要一个形式AccessibleAWTTextArea。 如有必要,将创建一个新的AccessibleAWTTextArea实例。- Specified by:
-
getAccessibleContext,界面Accessible - 重写:
-
getAccessibleContext在类TextComponent - 结果
-
AccessibleAWTTextArea,作为AccessibleContext的TextArea - 从以下版本开始:
- 1.3
-
-