public class JTextArea extends JTextComponent
JTextAreaは、プレーン・テキストを表示する複数行の領域です。 この処理を適切に行うjava.awt.TextAreaクラスとのソースの互換性を提供する軽量コンポーネントとして用意されています。 テキスト・コンポーネントの詳細および例については、「The Java Tutorial」の「Using Text Components」を参照してください。
このコンポーネントは、java.awt.TextAreaクラスにはない機能を備えています。 追加機能については、スーパー・クラスを参照してください。 より多くの機能を備えた複数行テキスト・クラスとして、ほかにJTextPaneとJEditorPaneがあります。
java.awt.TextAreaは内部的にスクロールを処理します。 JTextAreaはスクロールを管理しない点では異なりますが、SwingのScrollableインタフェースを実装します。 これにより、そのインタフェースをスクロール動作が必要な場合にJScrollPaneの内部に配置し、スクロールの動作が不要な場合に直接使えるようにできます。
java.awt.TextAreaは行折返しを行う機能を備えています。 これは、水平スクロール・ポリシーで制御されていました。 スクロールはJTextAreaによって直接実行されないため、下位互換性は別の方法で提供される必要があります。 JTextAreaには、行を折り返すかどうかを制御する行折返しのバウンド・プロパティがあります。 デフォルトでは、行折返しプロパティはfalse (折り返さない)に設定されています。
java.awt.TextAreaには、適切なサイズを指定するために使用されるrowsおよびcolumnsの2つのプロパティがあります。 JTextAreaはこれらのプロパティを使って、java.awt.TextAreaで提供される機能と一致するようにJScrollPaneの内部にビュー・ポートを配置する際の適切なサイズを示します。 JTextAreaには、テキストすべての表示に必要となる最適なサイズが用意されているので、ビュー・ポートはJScrollPaneの内部で適切に機能します。 rowsまたはcolumnsの値が0のとき、その軸に沿った最適なサイズが、同じ軸に沿ったビュー・ポートの適切なサイズに使用されます。
java.awt.TextAreaの変更を監視するには、TextEventのTextListenerを追加します。 JTextComponentベースのコンポーネントでは、DocumentEvent経由でモデルからDocumentListenersに変更が送られます。 DocumentEventは、必要に応じて、変更位置と変更の種類を提供します。 この部分のコードは次のようになります。
DocumentListener myListener = ??;
JTextArea myArea = ??;
myArea.getDocument().addDocumentListener(myListener);
警告: Swingはスレッドに対して安全ではありません。 詳細は、「Swing's Threading Policy」を参照してください。
警告: このクラスの直列化されたオブジェクトは、今後のSwingリリースと互換ではなくなる予定です。 現在の直列化のサポートは、短期間の格納や、同じバージョンのSwingを実行するアプリケーション間のRMIに適しています。 1.4以降、すべてのJavaBeans™用の長期間の格納サポートがjava.beansパッケージに追加されています。 XMLEncoderを参照してください。
JTextPane, JEditorPane| 修飾子と型 | クラス | 説明 |
|---|---|---|
protected class |
JTextArea.AccessibleJTextArea |
このクラスは
JTextAreaクラスのアクセシビリティ・サポートを実装しています。 |
JTextComponent.AccessibleJTextComponent, JTextComponent.DropLocation, JTextComponent.KeyBindingJComponent.AccessibleJComponentContainer.AccessibleAWTContainerComponent.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategyDEFAULT_KEYMAP, FOCUS_ACCELERATOR_KEYlistenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWaccessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH| コンストラクタ | 説明 |
|---|---|
JTextArea() |
新しいTextAreaを構築します。
|
JTextArea(Document doc) |
指定されたドキュメント・モデルと、ほかの引数はすべてデフォルト(null, 0, 0)で、新しいJTextAreaを構築します。
|
JTextArea(Document doc, String text, int rows, int columns) |
指定された行数と列数、および指定されたモデルで新しいJTextAreaを構築します。
|
JTextArea(int rows, int columns) |
指定された行数と列数で新しい空のTextAreaを構築します。
|
JTextArea(String text) |
指定された表示テキストで新しいTextAreaを構築します。
|
JTextArea(String text, int rows, int columns) |
指定されたテキストと行数と列数で新しいTextAreaを構築します。
|
| 修飾子と型 | メソッド | 説明 |
|---|---|---|
void |
append(String str) |
指定されたテキストをドキュメントの末尾に追加します。
|
protected Document |
createDefaultModel() |
モデルが明示的に指定されない場合は、構築時に使うモデルのデフォルト実装を作成します。
|
AccessibleContext |
getAccessibleContext() |
このJTextAreaに関連付けられたAccessibleContextを取得します。
|
int |
getColumns() |
TextArea内の列数を返します。
|
protected int |
getColumnWidth() |
列幅を返します。
|
int |
getLineCount() |
領域内に収める行数を返します。
|
int |
getLineEndOffset(int line) |
指定された行の終了オフセットを返します。
|
int |
getLineOfOffset(int offset) |
コンポーネント・テキストのオフセットを行番号に変換します。
|
int |
getLineStartOffset(int line) |
指定された行の開始オフセットを返します。
|
boolean |
getLineWrap() |
テキスト領域の行折返しポリシーを返します。
|
Dimension |
getPreferredScrollableViewportSize() |
このコンポーネントがJScrollPaneに組み込まれている場合はビュー・ポートの適切なサイズを返します。
|
Dimension |
getPreferredSize() |
TextAreaの適切なサイズを返します。
|
protected int |
getRowHeight() |
行の高さの意味を返します。
|
int |
getRows() |
TextArea内の行数を返します。
|
boolean |
getScrollableTracksViewportWidth() |
ビュー・ポートが常にこのScrollableの幅を強制的にビュー・ポートの幅に一致させる場合にtrueを返します。
|
int |
getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) |
論理行または論理列を表示するコンポーネントは、orientationの値によって、新しい1行または1列を完全にエクスポーズするスクロール増分値を計算します。
|
int |
getTabSize() |
タブを展開する文字数を取得します。
|
String |
getUIClassID() |
UIのクラスIDを返します。
|
boolean |
getWrapStyleWord() |
テキスト領域が折返し行の場合に使う折返し書式を返します。
|
void |
insert(String str, int pos) |
指定されたテキストを指定の位置に挿入します。
|
protected String |
paramString() |
このJTextAreaの文字列表現を返します。
|
void |
replaceRange(String str, int start, int end) |
指定された開始位置から終了位置までのテキストを、新しい指定テキストで置き換えます。
|
void |
setColumns(int columns) |
このTextAreaの列数を設定します。
|
void |
setFont(Font f) |
現在のフォントを設定します。
|
void |
setLineWrap(boolean wrap) |
テキスト領域の行折返しポリシーを設定します。
|
void |
setRows(int rows) |
このTextAreaの行数を設定します。
|
void |
setTabSize(int size) |
タブを展開する文字数を設定します。
|
void |
setWrapStyleWord(boolean word) |
テキスト領域が折返し行の場合に使う折返し書式を設定します。
|
addCaretListener, addInputMethodListener, addKeymap, copy, cut, fireCaretUpdate, getActions, getCaret, getCaretColor, getCaretListeners, getCaretPosition, getDisabledTextColor, getDocument, getDragEnabled, getDropLocation, getDropMode, getFocusAccelerator, getHighlighter, getInputMethodRequests, getKeymap, getKeymap, getMargin, getNavigationFilter, getPrintable, getScrollableBlockIncrement, getScrollableTracksViewportHeight, getSelectedText, getSelectedTextColor, getSelectionColor, getSelectionEnd, getSelectionStart, getText, getText, getToolTipText, getUI, isEditable, loadKeymap, modelToView, moveCaretPosition, paste, print, print, print, processInputMethodEvent, read, removeCaretListener, removeKeymap, removeNotify, replaceSelection, restoreComposedText, saveComposedText, select, selectAll, setCaret, setCaretColor, setCaretPosition, setComponentOrientation, setDisabledTextColor, setDocument, setDragEnabled, setDropMode, setEditable, setFocusAccelerator, setHighlighter, setKeymap, setMargin, setNavigationFilter, setSelectedTextColor, setSelectionColor, setSelectionEnd, setSelectionStart, setText, setUI, updateUI, viewToModel, writeaddAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, updateadd, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTreeaction, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCyclepublic JTextArea()
public JTextArea(String text)
text - 表示されるテキストまたはnullpublic JTextArea(int rows,
int columns)
rows - 行数>= 0columns - 列数>= 0IllegalArgumentException - 行または列の引数が負の数の場合。public JTextArea(String text, int rows, int columns)
text - 表示されるテキストまたはnullrows - 行数>= 0columns - 列数>= 0IllegalArgumentException - 行または列の引数が負の数の場合。public JTextArea(Document doc)
doc - 使用するモデルpublic JTextArea(Document doc, String text, int rows, int columns)
doc - 使用するモデル。ただしnullの場合は、デフォルト・モデルを作成するtext - 表示されるテキスト。ない場合はnullrows - 行数>= 0columns - 列数>= 0IllegalArgumentException - 行または列の引数が負の数の場合。public String getUIClassID()
getUIClassID、クラスJComponentJComponent.getUIClassID(), UIDefaults.getUI(javax.swing.JComponent)protected Document createDefaultModel()
public void setTabSize(int size)
size - 展開する文字数getTabSize()public int getTabSize()
public void setLineWrap(boolean wrap)
PropertyChangeイベント(lineWrap)が発生します。 デフォルトではこのプロパティはfalseです。 wrap - 行を折り返すかどうかを示すgetLineWrap()public boolean getLineWrap()
public void setWrapStyleWord(boolean word)
word - 行折返しにワード境界を使用するかどうかを示すgetWrapStyleWord()public boolean getWrapStyleWord()
setWrapStyleWord(boolean)public int getLineOfOffset(int offset)
throws BadLocationException
offset - オフセット>= 0BadLocationException - オフセットが0より小さい場合、またはドキュメントの長さより大きい場合。public int getLineCount()
public int getLineStartOffset(int line)
throws BadLocationException
line - 変換対象の行番号>= 0BadLocationException - 行が0より小さい場合、またはドキュメントに含まれる行数(getLineCountから報告される)以上である場合にスローされる。public int getLineEndOffset(int line)
throws BadLocationException
line - 行>= 0BadLocationException - 行が0より小さい場合、またはドキュメントに含まれる行数(getLineCountから報告される)以上である場合にスローされる。public void insert(String str, int pos)
str - 挿入するテキストpos - 挿入位置>= 0IllegalArgumentException - posがモデル内の無効な位置にある場合TextComponent.setText(java.lang.String), replaceRange(java.lang.String, int, int)public void append(String str)
str - 挿入するテキストinsert(java.lang.String, int)public void replaceRange(String str, int start, int end)
str - 置換えに使用するテキストstart - 開始位置>= 0end - 終了位置>= startIllegalArgumentException - 範囲の一部がモデル内の無効な位置にある場合insert(java.lang.String, int)public int getRows()
public void setRows(int rows)
rows - 行数>= 0IllegalArgumentException - 行が0より小さい場合getRows()protected int getRowHeight()
public int getColumns()
public void setColumns(int columns)
columns - 列数>= 0IllegalArgumentException - columns 0より小さい場合getColumns()protected int getColumnWidth()
public Dimension getPreferredSize()
getPreferredSize、クラスJComponentJComponent.setPreferredSize(java.awt.Dimension), ComponentUIpublic void setFont(Font f)
setFont、クラスJComponentf - 現在のフォントとして使うフォントComponent.getFont()protected String paramString()
nullにはなりません。 paramString、クラスJTextComponentpublic boolean getScrollableTracksViewportWidth()
getScrollableTracksViewportWidth、インタフェースScrollablegetScrollableTracksViewportWidth、クラスJTextComponentpublic Dimension getPreferredScrollableViewportSize()
getPreferredScrollableViewportSize、インタフェースScrollablegetPreferredScrollableViewportSize、クラスJTextComponentJComponent.getPreferredSize()public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction)
getRowHeightメソッドとgetColumnWidthメソッドが返す値を使うことができます。
JScrollPaneなどのスクロール・コンテナは、ユーザーがユニット・スクロールを要求すると、このメソッドを使用します。
getScrollableUnitIncrement、インタフェースScrollablegetScrollableUnitIncrement、クラスJTextComponentvisibleRect - ビュー・ポート内の可視のビュー領域orientation - SwingConstants.VERTICALまたはSwingConstants.HORIZONTAL。direction - 上または左にスクロールする場合は0より小さく、下または右にスクロールする場合は0より大きい。IllegalArgumentException - 方向が無効な場合JScrollBar.setUnitIncrement(int), getRowHeight(), getColumnWidth()public AccessibleContext getAccessibleContext()
getAccessibleContext、インタフェースAccessiblegetAccessibleContext、クラスJTextComponent バグまたは機能を送信
詳細なAPIリファレンスおよび開発者ドキュメントについては、Java SEのドキュメントを参照してください。 そのドキュメントには、概念的な概要、用語の定義、回避方法、有効なコード例などの、開発者を対象にしたより詳細な説明が含まれています。
Copyright © 1993, 2025, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Documentation Redistribution Policyも参照してください。