- 所有已实现的接口:
ImageObserver,MenuContainer,Serializable,Accessible,Scrollable
@JavaBean (description ="A text component that can be marked up with attributes that are graphically represented.") public class JTextPane extends JEditorPane
可以用图形表示的属性标记的文本组件。您可以在 使用文本组件 中找到使用文本窗格的操作方法信息和示例,这是 The Java Tutorial. 中的一个部分
该组件对由一系列字符级属性组成的段落建模。每个段落都可以附加一个逻辑样式,其中包含要使用的默认属性,如果没有被段落或字符运行上设置的属性重写的话。组件和图像可以嵌入到文本流中。
- 换行符
- 有关如何处理换行符的讨论,请参阅 DefaultEditorKit。
Warning: Swing 不是线程安全的。有关详细信息,请参阅 Swing 的线程策略。
Warning: 此类的序列化对象将与未来的 Swing 版本不兼容。当前的序列化支持适用于运行相同版本 Swing 的应用程序之间的短期存储或 RMI。从 1.4 开始,对所有 JavaBeans 的长期存储的支持已添加到 java.beans 包中。请参阅 XMLEncoder 。
- 自从:
- 1.2
- 参见:
-
内部类总结
在类 javax.swing.JEditorPane 中声明的嵌套类/接口
JEditorPane.AccessibleJEditorPane, JEditorPane.AccessibleJEditorPaneHTML, JEditorPane.JEditorPaneAccessibleHypertextSupport在类 javax.swing.text.JTextComponent 中声明的嵌套类/接口
JTextComponent.AccessibleJTextComponent, JTextComponent.DropLocation, JTextComponent.KeyBinding在类 javax.swing.JComponent 中声明的嵌套类/接口
JComponent.AccessibleJComponent在类 java.awt.Container 中声明的嵌套类/接口
Container.AccessibleAWTContainer -
字段摘要
在类 javax.swing.JEditorPane 中声明的字段
HONOR_DISPLAY_PROPERTIES, W3C_LENGTH_UNITS在类 javax.swing.text.JTextComponent 中声明的字段
DEFAULT_KEYMAP, FOCUS_ACCELERATOR_KEY在类 javax.swing.JComponent 中声明的字段
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW在类 java.awt.Component 中声明的字段
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT在接口 java.awt.image.ImageObserver 中声明的字段
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH -
构造方法总结
构造方法 -
方法总结
修饰符和类型方法描述将新样式添加到逻辑样式层次结构中。protected EditorKit创建默认使用的EditorKit。获取在插入符号或null的当前位置有效的字符属性。获取窗格的输入属性。获取分配给由插入符号的当前位置或null表示的段落的逻辑样式。获取在插入符号位置有效的当前段落属性,如果没有则为null。获取先前添加的命名非null样式。获取与编辑器关联的模型。protected final StyledEditorKit获取编辑器工具包。返回 UI 的类 ID。void将组件插入到文档中以替换当前选定的内容。voidinsertIcon(Icon g) 将图标插入到文档中以替换当前选定的内容。protected String返回此JTextPane的字符串表示形式voidremoveStyle(String nm) 删除以前添加到文档中的命名非null样式。voidreplaceSelection(String content) 用给定字符串表示的新内容替换当前选择的内容。voidsetCharacterAttributes(AttributeSet attr, boolean replace) 将给定的属性应用于字符内容。voidsetDocument(Document doc) 将编辑器与文本文档相关联。final voidsetEditorKit(EditorKit kit) 设置当前安装的用于处理内容的工具包。void设置用于当前插入符号位置的段落的逻辑样式。voidsetParagraphAttributes(AttributeSet attr, boolean replace) 将给定的属性应用于段落。void将编辑器与文本文档相关联。在类 javax.swing.JEditorPane 中声明的方法
addHyperlinkListener, createEditorKitForContentType, fireHyperlinkUpdate, getAccessibleContext, getContentType, getEditorKit, getEditorKitClassNameForContentType, getEditorKitForContentType, getHyperlinkListeners, getPage, getPreferredSize, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getStream, getText, read, registerEditorKitForContentType, registerEditorKitForContentType, removeHyperlinkListener, scrollToReference, setContentType, setEditorKitForContentType, setPage, setPage, setText在类 javax.swing.text.JTextComponent 中声明的方法
addCaretListener, addKeymap, copy, cut, fireCaretUpdate, getActions, getCaret, getCaretColor, getCaretListeners, getCaretPosition, getDisabledTextColor, getDocument, getDragEnabled, getDropLocation, getDropMode, getFocusAccelerator, getHighlighter, getInputMethodRequests, getKeymap, getKeymap, getMargin, getNavigationFilter, getPreferredScrollableViewportSize, getPrintable, getScrollableBlockIncrement, getScrollableUnitIncrement, getSelectedText, getSelectedTextColor, getSelectionColor, getSelectionEnd, getSelectionStart, getText, getToolTipText, getUI, isEditable, loadKeymap, modelToView, modelToView2D, moveCaretPosition, paste, print, print, print, read, removeCaretListener, removeKeymap, restoreComposedText, saveComposedText, select, selectAll, setCaret, setCaretColor, setCaretPosition, setDisabledTextColor, setDragEnabled, setDropMode, setEditable, setFocusAccelerator, setHighlighter, setKeymap, setMargin, setNavigationFilter, setSelectedTextColor, setSelectionColor, setSelectionEnd, setSelectionStart, setUI, updateUI, viewToModel, viewToModel2D, write在类 javax.swing.JComponent 中声明的方法
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, 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, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update在类 java.awt.Container 中声明的方法
add, 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, validateTree在类 java.awt.Component 中声明的方法
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, 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, 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, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
构造方法详细信息
-
JTextPane
public JTextPane()创建一个新的JTextPane。创建并设置StyledEditorKit的新实例,并将文档模型设置为null。 -
JTextPane
使用指定的文档模型创建一个新的JTextPane。创建并设置javax.swing.text.StyledEditorKit的新实例。- 参数:
doc- 文档模型
-
-
方法详情
-
getUIClassID
返回 UI 的类 ID。- 重写:
getUIClassID在类JEditorPane中- 返回:
- 字符串“TextPaneUI”
- 参见:
-
setDocument
将编辑器与文本文档相关联。这必须是StyledDocument。- 重写:
setDocument在类JTextComponent中- 参数:
doc- 要显示/编辑的文档- 抛出:
IllegalArgumentException- 如果doc不能缩小为StyledDocument,这是此文本组件所需的模型类型- 参见:
-
setStyledDocument
将编辑器与文本文档相关联。当前注册的工厂用于为文档构建视图,该视图由编辑器显示。- 参数:
doc- 要显示/编辑的文档
-
getStyledDocument
获取与编辑器关联的模型。- 返回:
- 该模型
-
replaceSelection
用给定字符串表示的新内容替换当前选择的内容。如果没有选择,这相当于给定文本的插入。如果没有替换文本,这相当于删除当前选择。替换文本将具有当前为插入点输入定义的属性。如果文档不可编辑,发出哔哔声并返回。- 重写:
replaceSelection在类JEditorPane中- 参数:
content- 用来替换选择的内容
-
insertComponent
将组件插入到文档中以替换当前选定的内容。如果没有选择,组件将有效地插入插入符号的当前位置。这在相关文档中表示为内容的一个字符的属性。给定的组件是 JTextPane 使用的实际组件。由于组件不能是多个容器的子组件,因此不应在文本组件共享模型的情况下使用此方法。
根据
Component.getAlignmentY返回的值,组件相对于文本基线放置。对于 Swing 组件,可以使用方法JComponent.setAlignmentY方便地设置此值。例如,设置值0.75将导致 75% 的组件高于基线,25% 的组件低于基线。- 参数:
c- 要插入的组件
-
insertIcon
将图标插入到文档中以替换当前选定的内容。如果没有选择,图标将有效地插入到插入符号的当前位置。这在相关文档中表示为内容的一个字符的属性。- 参数:
g- 要插入的图标- 参见:
-
addStyle
将新样式添加到逻辑样式层次结构中。样式属性从下到上解析,因此在子项中指定的属性将重写在父项中指定的属性。- 参数:
nm- 样式名称(在命名样式集合中必须是唯一的)。如果样式未命名,名称可能是null,但调用者负责管理返回的引用,因为无法通过名称获取未命名样式。未命名的样式可能对诸如字符属性覆盖之类的事情很有用,例如在样式运行中发现的。parent- 父样式。这可能是null如果未指定的属性不需要以其他方式解析。- 返回:
-
新的
Style
-
removeStyle
删除以前添加到文档中的命名非null样式。- 参数:
nm- 要删除的样式的名称
-
getStyle
获取先前添加的命名非null样式。- 参数:
nm- 样式名称- 返回:
Style
-
setLogicalStyle
设置用于当前插入符号位置的段落的逻辑样式。如果没有为字符和段落属性明确设置属性,它们将通过分配给段落的逻辑样式来解析,这在术语中可以通过一些完全独立于文档中元素层次结构的层次结构来解析。- 参数:
s- 分配给段落的逻辑样式,或null无样式
-
getLogicalStyle
获取分配给由插入符号的当前位置或null表示的段落的逻辑样式。- 返回:
Style
-
getCharacterAttributes
获取在插入符号或null的当前位置有效的字符属性。- 返回:
-
属性,或
null
-
setCharacterAttributes
将给定的属性应用于字符内容。如果有选择,属性将应用于选择范围。如果没有选择,属性将应用于定义插入的任何新文本的属性的输入属性集。- 参数:
attr- 属性replace- 如果为真,则首先替换现有属性
-
getParagraphAttributes
获取在插入符号位置有效的当前段落属性,如果没有则为null。- 返回:
- 属性
-
setParagraphAttributes
将给定的属性应用于段落。如果有选择,属性将应用于与选择相交的段落。如果没有选择,属性将应用于当前插入符位置的段落。- 参数:
attr- 非null属性replace- 如果为真,首先替换现有属性
-
getInputAttributes
获取窗格的输入属性。- 返回:
- 属性
-
getStyledEditorKit
获取编辑器工具包。- 返回:
- 编辑器套件
-
createDefaultEditorKit
创建默认使用的EditorKit。这是为了返回javax.swing.text.StyledEditorKit而实现的。- 重写:
createDefaultEditorKit在类JEditorPane中- 返回:
- 编辑器套件
-
setEditorKit
设置当前安装的用于处理内容的工具包。这是建立编辑器内容类型的绑定属性。- 重写:
setEditorKit在类JEditorPane中- 参数:
kit- 所需的编辑器行为- 抛出:
IllegalArgumentException- 如果套件不是StyledEditorKit- 参见:
-
paramString
返回此JTextPane的字符串表示形式。此方法仅用于调试目的,返回字符串的内容和格式可能因实现而异。返回的字符串可能为空,但可能不是null。- 重写:
paramString在类JEditorPane中- 返回:
-
这个
JTextPane的字符串表示
-