JavaTM 2 Platform
Std. Ed. v1.3

javax.swing
クラス JTextPane

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--javax.swing.text.JTextComponent
                          |
                          +--javax.swing.JEditorPane
                                |
                                +--javax.swing.JTextPane
すべての実装インタフェース:
Accessible, ImageObserver, MenuContainer, Scrollable, Serializable

public class JTextPane
extends JEditorPane

グラフィックで表現される属性でマークアップできるテキストコンポーネントです。使用方法およびテキスト区画の例については、「The Java Tutorial」の「Using Text Components」セクションを参照してください。

このコンポーネントは、文字レベル属性の並びから構成される段落をモデル化します。各段落には、段落または文字の並びに設定される属性によってオーバーライドされないかぎり使用される、デフォルト属性を収めた論理書式が付属しています。コンポーネントとイメージは、テキストの中に組み込むことができます。

標準の Look & Feel (L&F) 表現でこのコンポーネントが使用するキーボードのキーについては、JTextPane のキーの割り当てを参照してください。

警告: このクラスの直列化されたオブジェクトは、今後の Swing リリースと互換ではなくなる予定です。現在の直列化のサポートは、短期間の運用や、同じバージョンの Swing を実行するアプリケーション間の RMI に適しています。今後の Swing リリースでは、長期間の持続性をサポートする予定です。

関連項目:
StyledEditorKit, 直列化された形式

クラス javax.swing.JEditorPane から継承した内部クラス
JEditorPane.AccessibleJEditorPane, JEditorPane.AccessibleJEditorPaneHTML, JEditorPane.JEditorPaneAccessibleHypertextSupport
 
クラス javax.swing.text.JTextComponent から継承した内部クラス
JTextComponent.AccessibleJTextComponent, JTextComponent.KeyBinding
 
クラス javax.swing.JComponent から継承した内部クラス
JComponent.AccessibleJComponent
 
クラス java.awt.Container から継承した内部クラス
Container.AccessibleAWTContainer
 
クラス java.awt.Component から継承した内部クラス
Component.AccessibleAWTComponent
 
クラス javax.swing.text.JTextComponent から継承したフィールド
DEFAULT_KEYMAP, FOCUS_ACCELERATOR_KEY
 
クラス javax.swing.JComponent から継承したフィールド
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
クラス java.awt.Component から継承したフィールド
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
インタフェース java.awt.image.ImageObserver から継承したフィールド
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
コンストラクタの概要
JTextPane()
          新しい JTextPane を構築します。
JTextPane(StyledDocument doc)
          新規 JTextPane を指定されたドキュメントモデルで構築します。
 
メソッドの概要
 Style addStyle(String nm, Style parent)
          論理書式階層に新しい書式を追加します。
protected  EditorKit createDefaultEditorKit()
          デフォルトで使う EditorKit を作成します。
 AttributeSet getCharacterAttributes()
          現在のキャレット位置で有効な文字属性がある場合はそれを返します。
 MutableAttributeSet getInputAttributes()
          区画の入力属性を返します。
 Style getLogicalStyle()
          現在のキャレット位置で表される段落に割り当てられている論理書式がある場合はそれを返します。
 AttributeSet getParagraphAttributes()
          キャレット位置で有効な現在の段落属性がある場合はそれを返します。
 Style getStyle(String nm)
          それまでに追加済みの無効でない名前付き書式を返します。
 StyledDocument getStyledDocument()
          エディタに関連したモデルを返します。
protected  StyledEditorKit getStyledEditorKit()
          エディタキットを返します。
 String getUIClassID()
          UI のクラス ID を返します。
 void insertComponent(Component c)
          現在選択されているコンテンツの置換後の内容としてドキュメントにコンポーネントを挿入します。
 void insertIcon(Icon g)
          現在選択されているコンテンツの置換後の内容としてドキュメントにアイコンを挿入します。
protected  String paramString()
          この JTextPane の文字列表現を返します。
 void removeStyle(String nm)
          ドキュメントにそれまでに追加済みの無効でない名前付き書式を削除します。
 void replaceSelection(String content)
          現在選択されているコンテンツを、指定された文字列で表された新しいコンテンツで置き換えます。
 void setCharacterAttributes(AttributeSet attr, boolean replace)
          指定された属性を文字コンテンツに適用します。
 void setDocument(Document doc)
          エディタをテキストドキュメントに関連付けます。
 void setEditorKit(EditorKit kit)
          コンテンツを処理するために現在インストールされているキットを設定します。
 void setLogicalStyle(Style s)
          段落に使う論理書式を現在のキャレット位置に設定します。
 void setParagraphAttributes(AttributeSet attr, boolean replace)
          指定された属性を段落に適用します。
 void setStyledDocument(StyledDocument doc)
          エディタをテキストドキュメントに関連付けます。
 
クラス javax.swing.JEditorPane から継承したメソッド
addHyperlinkListener, createEditorKitForContentType, fireHyperlinkUpdate, getAccessibleContext, getContentType, getEditorKit, getEditorKitClassNameForContentType, getEditorKitForContentType, getPage, getPreferredSize, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getStream, getText, isFocusCycleRoot, isManagingFocus, processComponentKeyEvent, processKeyEvent, read, registerEditorKitForContentType, registerEditorKitForContentType, removeHyperlinkListener, scrollToReference, setContentType, setEditorKitForContentType, setPage, setPage, setText
 
クラス javax.swing.text.JTextComponent から継承したメソッド
addCaretListener, addInputMethodListener, addKeymap, copy, cut, fireCaretUpdate, getActions, getCaret, getCaretColor, getCaretPosition, getDisabledTextColor, getDocument, getFocusAccelerator, getHighlighter, getInputMethodRequests, getKeymap, getKeymap, getMargin, getPreferredScrollableViewportSize, getScrollableBlockIncrement, getScrollableUnitIncrement, getSelectedText, getSelectedTextColor, getSelectionColor, getSelectionEnd, getSelectionStart, getText, getUI, isEditable, isFocusTraversable, loadKeymap, modelToView, moveCaretPosition, paste, processInputMethodEvent, read, removeCaretListener, removeKeymap, removeNotify, select, selectAll, setCaret, setCaretColor, setCaretPosition, setDisabledTextColor, setEditable, setFocusAccelerator, setHighlighter, setKeymap, setMargin, setSelectedTextColor, setSelectionColor, setSelectionEnd, setSelectionStart, setUI, updateUI, viewToModel, write
 
クラス javax.swing.JComponent から継承したメソッド
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getVerifyInputWhenFocusTarget, getVisibleRect, getWidth, getX, getY, grabFocus, hasFocus, hide, isDoubleBuffered, isLightweightComponent, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processFocusEvent, processKeyBinding, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
クラス java.awt.Container から継承したメソッド
add, add, add, add, add, addContainerListener, addImpl, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getLayout, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setLayout, validate, validateTree
 
クラス java.awt.Component から継承したメソッド
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addKeyListener, addMouseListener, addMouseMotionListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getInputContext, getLocale, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, imageUpdate, inside, isDisplayable, isEnabled, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processHierarchyBoundsEvent, processHierarchyEvent, processMouseEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus
 
クラス java.lang.Object から継承したメソッド
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

コンストラクタの詳細

JTextPane

public JTextPane()
新しい JTextPane を構築します。StyledEditorKit の新しいインスタンスが生成および設定され、ドキュメントモデルは無効に設定されます。

JTextPane

public JTextPane(StyledDocument doc)
新規 JTextPane を指定されたドキュメントモデルで構築します。javax.swing.text.StyledEditorKit の新しいインスタンスが生成および設定されます。
パラメータ:
doc - ドキュメントモデル
メソッドの詳細

getUIClassID

public String getUIClassID()
UI のクラス ID を返します。
オーバーライド:
クラス JEditorPane 内の getUIClassID
戻り値:
ID ("TextPaneUI")
関連項目:
JComponent.getUIClassID(), UIDefaults.getUI(javax.swing.JComponent)

setDocument

public void setDocument(Document doc)
エディタをテキストドキュメントに関連付けます。これは StyledDocument でなければなりません。
オーバーライド:
クラス JTextComponent 内の setDocument
パラメータ:
doc - 表示および編集するドキュメント
例外:
IllegalArgumentException - doc をこのテキストコンポーネントに必要なタイプのモデルである StyledDocument にナロー変換できない場合

setStyledDocument

public void setStyledDocument(StyledDocument doc)
エディタをテキストドキュメントに関連付けます。現在登録されているファクトリを使うと、ドキュメントのビューを構築できます。このドキュメントは、エディタによって表示されます。
パラメータ:
doc - 表示および編集するドキュメント

getStyledDocument

public StyledDocument getStyledDocument()
エディタに関連したモデルを返します。
戻り値:
モデル

replaceSelection

public void replaceSelection(String content)
現在選択されているコンテンツを、指定された文字列で表された新しいコンテンツで置き換えます。選択領域がない場合、これは指定されたテキストの挿入に相当します。 置換後のテキストがない場合、これは現在の選択領域の削除に相当します。置換後のテキストには、入力用に現在定義されている属性が設定されます。コンポーネントが編集できない状態であれば、ビープ音が鳴って復帰改行します。ドキュメントが無効な場合は何も行いません。挿入するコンテンツが無効か空の場合は、それを無視します。

このメソッドはスレッドに対して安全ですが、ほとんどの Swing メソッドは違います。詳細は、「Threads and Swing」を参照してください。

オーバーライド:
クラス JEditorPane 内の replaceSelection
パラメータ:
content - 選択範囲を置き換えるコンテンツ

insertComponent

public void insertComponent(Component c)
現在選択されているコンテンツの置換後の内容としてドキュメントにコンポーネントを挿入します。選択領域がない場合、コンポーネントは事実上、キャレットの現在の位置に挿入されます。これは、関連したドキュメントでコンテンツの 1 文字の属性として表現されます。
パラメータ:
c - 挿入されるコンポーネント

insertIcon

public void insertIcon(Icon g)
現在選択されているコンテンツの置換後の内容としてドキュメントにアイコンを挿入します。選択領域がない場合、アイコンは事実上、キャレットの現在の位置に挿入されます。これは、関連したドキュメントでコンテンツの 1 文字の属性として表現されます。

このメソッドはスレッドに対して安全ですが、ほとんどの Swing メソッドは違います。詳細は、「Threads and Swing」を参照してください。

パラメータ:
g - 挿入されるアイコン
関連項目:
Icon

addStyle

public Style addStyle(String nm,
                      Style parent)
論理書式階層に新しい書式を追加します。書式の属性は下から上に向かって解釈処理されるので、子で指定された属性は親で指定された属性をオーバーライドします。
パラメータ:
nm - 書式の名前。この名前は、名前付き書式のコレクションの中で一意でなければならない。名前は、書式に名前が付いていない場合は null も可能だが、呼び出し側は名前のない書式が名前で取得できない場合に返される参照を管理しなければならない。名前のない書式は、スタイルランで見られるような文字属性のオーバーライドなどで便利な場合がある
parent - 親書式。指定されていない属性がほかの書式で解釈処理される必要がない場合は null も可
戻り値:
新規 Style

removeStyle

public void removeStyle(String nm)
ドキュメントにそれまでに追加済みの無効でない名前付き書式を削除します。
パラメータ:
nm - 削除される書式の名前

getStyle

public Style getStyle(String nm)
それまでに追加済みの無効でない名前付き書式を返します。
パラメータ:
nm - 書式の名前
戻り値:
書式

setLogicalStyle

public void setLogicalStyle(Style s)
段落に使う論理書式を現在のキャレット位置に設定します。属性が文字属性や段落属性として明示的に設定されない場合、段落に割り当てられた論理書式を介して解釈処理されます。そして今度は論理書式が、ドキュメント内の要素階層から完全に独立した特定の階層を解釈処理します。

このメソッドはスレッドに対して安全ですが、ほとんどの Swing メソッドは違います。詳細は、「Threads and Swing」を参照してください。

パラメータ:
s - 段落に割り当てる論理書式。書式なしの場合は null

getLogicalStyle

public Style getLogicalStyle()
現在のキャレット位置で表される段落に割り当てられている論理書式がある場合はそれを返します。ない場合は null を返します。
戻り値:
書式

getCharacterAttributes

public AttributeSet getCharacterAttributes()
現在のキャレット位置で有効な文字属性がある場合はそれを返します。ない場合は null を返します。
戻り値:
属性または null

setCharacterAttributes

public void setCharacterAttributes(AttributeSet attr,
                                   boolean replace)
指定された属性を文字コンテンツに適用します。選択がある場合、属性はその選択範囲に適用されます。選択がない場合、属性は、挿入される新しいテキストの属性を定義する入力属性セットに適用されます。

このメソッドはスレッドに対して安全ですが、ほとんどの Swing メソッドは違います。詳細は、「Threads and Swing」を参照してください。

パラメータ:
attr - 属性
replace - true の場合、既存の属性が最初に置き換えられる

getParagraphAttributes

public AttributeSet getParagraphAttributes()
キャレット位置で有効な現在の段落属性がある場合はそれを返します。ない場合は null を返します。
戻り値:
属性

setParagraphAttributes

public void setParagraphAttributes(AttributeSet attr,
                                   boolean replace)
指定された属性を段落に適用します。選択がある場合、属性はその選択と交わる段落に適用されます。選択がない場合、属性は現在のキャレット位置にある段落に適用されます。

このメソッドはスレッドに対して安全ですが、ほとんどの Swing メソッドは違います。詳細は、「Threads and Swing」を参照してください。

パラメータ:
attr - null 以外の属性
replace - true の場合、既存の属性が最初に置き換えられる

getInputAttributes

public MutableAttributeSet getInputAttributes()
区画の入力属性を返します。
戻り値:
属性

getStyledEditorKit

protected final StyledEditorKit getStyledEditorKit()
エディタキットを返します。
戻り値:
エディタキット

createDefaultEditorKit

protected EditorKit createDefaultEditorKit()
デフォルトで使う EditorKit を作成します。これを実装すると、javax.swing.text.StyledEditorKit を返します。
オーバーライド:
クラス JEditorPane 内の createDefaultEditorKit
戻り値:
エディタキット

setEditorKit

public final void setEditorKit(EditorKit kit)
コンテンツを処理するために現在インストールされているキットを設定します。これは、エディタのコンテンツのタイプを確定するバウンドプロパティです。
オーバーライド:
クラス JEditorPane 内の setEditorKit
パラメータ:
kit - 適切なエディタ動作
例外:
IllegalArgumentException - キットが StyledEditorKit ではない場合

paramString

protected String paramString()
この JTextPane の文字列表現を返します。このメソッドはデバッグ専用であり、返される文字列の内容および形式は実装によって異なります。返される文字列は空の場合がありますが、null にはなりません。
オーバーライド:
クラス JEditorPane 内の paramString
戻り値:
この JTextPane の文字列表現

JavaTM 2 Platform
Std. Ed. v1.3

バグや機能要求の報告
さらに詳しい API リファレンスおよび開発者ドキュメントについては、 Java 2 SDK SE Developer Documentation を参照してください。このドキュメントには、概念、用語の定義、回避策、 実用的なコード例など、開発者を対象にした詳細な解説が掲載されています。

Java、Java 2D、JDBC は、米国およびその他の国における米国 Sun Microsystems, Inc. の商標もしくは登録商標です。
Copyright 1993-2000 Sun Microsystems, Inc. 901 San Antonio Road,
Palo Alto, California, 94303, U.S.A. All Rights Reserved.