- 所有已实现的接口:
-
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
一个可以用图形表示属性的文本组件。您可以在使用文本组件中找到如何操作以及示例。这个组件模拟由字符级属性运行组成的段落。每个段落可能附有逻辑样式,其中包含默认属性,如果没有在段落或字符运行上设置属性,则使用这些属性。组件和图像可以嵌入到文本流中。
警告: Swing 不是线程安全的。更多信息请参阅Swing的线程策略。
警告: 该类的序列化对象将不兼容未来的 Swing 版本。当前的序列化支持适用于短期存储或在运行相同 Swing 版本的应用程序之间的 RMI。从 1.4 版开始,已将所有 JavaBeans 的长期存储支持添加到 java.beans
包中。请参阅XMLEncoder
。
- 自:
- 1.2
- 参见:
-
Nested Class Summary
Nested classes/interfaces declared in class javax.swing.JEditorPane
JEditorPane.AccessibleJEditorPane, JEditorPane.AccessibleJEditorPaneHTML, JEditorPane.JEditorPaneAccessibleHypertextSupport
Nested classes/interfaces declared in class javax.swing.text.JTextComponent
JTextComponent.AccessibleJTextComponent, JTextComponent.DropLocation, JTextComponent.KeyBinding
Nested classes/interfaces declared in class javax.swing.JComponent
JComponent.AccessibleJComponent
Nested classes/interfaces declared in class java.awt.Container
Container.AccessibleAWTContainer
Nested classes/interfaces declared in class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
Field Summary
Fields declared in class javax.swing.JEditorPane
HONOR_DISPLAY_PROPERTIES, W3C_LENGTH_UNITS
Fields declared in class javax.swing.text.JTextComponent
DEFAULT_KEYMAP, FOCUS_ACCELERATOR_KEY
Fields declared in class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
Fields declared in class 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
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescription将一个新样式添加到逻辑样式层次结构中。protected EditorKit
创建默认使用的EditorKit
。获取光标当前位置的字符属性,或null
。获取文本组件的输入属性。获取由光标当前位置表示的段落分配的逻辑样式,或null
。获取光标位置处当前段落的当前段落属性,如果没有则返回null
。获取先前添加的具有命名的非null
样式。获取与编辑器关联的模型。protected final StyledEditorKit
获取编辑器工具包。返回 UI 的类 ID。void
将组件插入文档,以替换当前选定的内容。void
insertIcon
(Icon g) 将图标插入文档,以替换当前选定的内容。protected String
返回此JTextPane
的字符串表示形式。void
removeStyle
(String nm) 从文档中删除先前添加的具有命名的非null
样式。void
replaceSelection
(String content) 用给定字符串表示的新内容替换当前选定的内容。void
setCharacterAttributes
(AttributeSet attr, boolean replace) 将给定属性应用于字符内容。void
setDocument
(Document doc) 将编辑器与文本文档关联。final void
setEditorKit
(EditorKit kit) 设置用于处理内容的当前安装的工具包。void
设置当前光标位置段落使用的逻辑样式。void
setParagraphAttributes
(AttributeSet attr, boolean replace) 将给定属性应用于段落。void
将编辑器与文本文档关联。Methods declared in class 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
Methods declared in class 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
Methods declared in class 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
Methods declared in class 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
Methods declared in class 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
-
Constructor Details
-
JTextPane
public JTextPane()创建一个新的JTextPane
。创建一个新的StyledEditorKit
实例并设置,文档模型设置为null
。 -
JTextPane
创建一个新的JTextPane
,带有指定的文档模型。创建一个新的javax.swing.text.StyledEditorKit
实例并设置。- 参数:
-
doc
- 文档模型
-
-
Method Details
-
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
- 如果为true,则首先替换现有属性
-
getParagraphAttributes
获取插入符位置处生效的当前段落属性,如果没有则返回null
。- 返回:
- 属性
-
setParagraphAttributes
将给定的属性应用于段落。如果存在选择,则将属性应用于与选择相交的段落。如果没有选择,则将属性应用于当前插入符位置的段落。- 参数:
-
attr
- 非null
属性 -
replace
- 如果为true,则首先替换现有属性
-
getInputAttributes
获取面板的输入属性。- 返回:
- 属性
-
getStyledEditorKit
获取编辑器工具包。- 返回:
- 编辑器工具包
-
createDefaultEditorKit
创建默认使用的EditorKit
。此方法实现为返回javax.swing.text.StyledEditorKit
。- 覆盖:
-
createDefaultEditorKit
在类JEditorPane
- 返回:
- 编辑器工具包
-
setEditorKit
设置当前安装的用于处理内容的工具包。这是建立编辑器内容类型的绑定属性。- 覆盖:
-
setEditorKit
在类JEditorPane
- 参数:
-
kit
- 所需的编辑器行为 - 抛出:
-
IllegalArgumentException
- 如果kit不是StyledEditorKit
- 参见:
-
paramString
返回此JTextPane
的字符串表示形式。此方法仅用于调试目的,返回的字符串的内容和格式可能因实现而异。返回的字符串可能为空,但不会是null
。- 覆盖:
-
paramString
在类JEditorPane
- 返回:
-
此
JTextPane
的字符串表示形式
-