public class JTextPane extends JEditorPane
该组件模拟由字符级属性运行组成的段落。 每个段落可能具有连接到其上的逻辑风格,其中包含默认属性,如果不被该段落或字符运行时设置的属性覆盖,则使用默认属性。 组件和图像可能嵌入在文本流中。
警告: Swing不是线程安全的。 有关更多信息,请参阅Swing's Threading Policy 。
警告:此类的序列化对象与将来的Swing版本不兼容。 当前的序列化支持适用于运行相同版本的Swing的应用程序之间的短期存储或RMI。 从1.4开始,对所有JavaBeans的长期存储的支持已经添加到java.beans包中。 请参阅XMLEncoder 。
StyledEditorKit
JEditorPane.AccessibleJEditorPane, JEditorPane.AccessibleJEditorPaneHTML, JEditorPane.JEditorPaneAccessibleHypertextSupportJTextComponent.AccessibleJTextComponent, JTextComponent.DropLocation, JTextComponent.KeyBindingJComponent.AccessibleJComponentContainer.AccessibleAWTContainerComponent.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategyHONOR_DISPLAY_PROPERTIES, W3C_LENGTH_UNITSDEFAULT_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| Constructor and Description |
|---|
JTextPane()
创建一个新的
JTextPane 。
|
JTextPane(StyledDocument doc)
创建一个新的
JTextPane ,具有指定的文档模型。
|
| Modifier and Type | Method and Description |
|---|---|
Style |
addStyle(String nm, Style parent)
在逻辑样式层次结构中添加新样式。
|
protected EditorKit |
createDefaultEditorKit()
创建默认使用的
EditorKit 。
|
AttributeSet |
getCharacterAttributes()
获取在插入符号的当前位置生效的字符
null ,或
null 。
|
MutableAttributeSet |
getInputAttributes()
获取窗格的输入属性。
|
Style |
getLogicalStyle()
获取分配给由插入符号的当前位置表示的段落的逻辑样式,或
null 。
|
AttributeSet |
getParagraphAttributes()
获取当前段落属性在插入符号的位置,或
null如果没有)。
|
Style |
getStyle(String nm)
获取以前添加的命名非
null样式。
|
StyledDocument |
getStyledDocument()
获取与编辑器相关联的模型。
|
protected StyledEditorKit |
getStyledEditorKit()
获得编辑工具包。
|
String |
getUIClassID()
返回UI的类ID。
|
void |
insertComponent(Component c)
将组件插入到文档中作为当前所选内容的替代。
|
void |
insertIcon(Icon g)
将图标插入到文档中作为当前所选内容的替代。
|
protected String |
paramString()
返回此
JTextPane的字符串表示
JTextPane 。
|
void |
removeStyle(String nm)
删除以前添加到文档的命名非
null样式。
|
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)
将编辑器与文本文档相关联。
|
addHyperlinkListener, createEditorKitForContentType, fireHyperlinkUpdate, getAccessibleContext, getContentType, getEditorKit, getEditorKitClassNameForContentType, getEditorKitForContentType, getHyperlinkListeners, getPage, getPreferredSize, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getStream, getText, read, registerEditorKitForContentType, registerEditorKitForContentType, removeHyperlinkListener, scrollToReference, setContentType, setEditorKitForContentType, setPage, setPage, setTextaddCaretListener, addInputMethodListener, 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, moveCaretPosition, paste, print, print, print, processInputMethodEvent, read, removeCaretListener, removeKeymap, removeNotify, restoreComposedText, saveComposedText, select, selectAll, setCaret, setCaretColor, setCaretPosition, setComponentOrientation, setDisabledTextColor, setDragEnabled, setDropMode, setEditable, setFocusAccelerator, setHighlighter, setKeymap, setMargin, setNavigationFilter, setSelectedTextColor, setSelectionColor, setSelectionEnd, setSelectionStart, 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, setFont, 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 JTextPane()
JTextPane 。
创建并设置了一个新的StyledEditorKit实例,并将文档模型设置为null 。
public JTextPane(StyledDocument doc)
JTextPane ,具有指定的文档模型。
创建并设置了一个新的javax.swing.text.StyledEditorKit实例。
doc - 文件模型
public String getUIClassID()
getUIClassID在
JEditorPane
JComponent.getUIClassID() ,
UIDefaults.getUI(javax.swing.JComponent)
public void setDocument(Document doc)
StyledDocument 。
setDocument在
JTextComponent
doc - 要显示/编辑的文档
IllegalArgumentException - 如果
doc不能缩小为
StyledDocument ,这是此文本组件所需的模型类型
JTextComponent.getDocument()
public void setStyledDocument(StyledDocument doc)
doc - 要显示/编辑的文档
public StyledDocument getStyledDocument()
public void replaceSelection(String content)
replaceSelection在
JEditorPane
content - 用于替换选择的内容
public void insertComponent(Component c)
给出的组件是JTextPane使用的实际组件。 由于组件不能是多个容器的子级,所以在模型由文本组件共享的情况下不应使用此方法。
该组件是根据返回的值,以相对于文本基线放置Component.getAlignmentY 。 对于Swing组件,可以使用方法JComponent.setAlignmentY方便地设置该值。 例如,设置值为0.75将导致75%的组件高于基线,25%的组件将低于基线。
c - 要插入的组件
public void insertIcon(Icon g)
g - 要插入的图标
Icon
public Style addStyle(String nm, Style parent)
nm - 样式的名称(在命名样式的集合中必须是唯一的)。
如果样式未命名,则名称可能为null ,但是调用者负责管理返回的引用,因为未命名的样式无法通过名称获取。
一个未命名的样式可能对于诸如字符属性覆盖(例如在样式运行中找到)的事情是有用的。
parent - 父风格。
这可能是null如果未指定的属性不需要解决某些其他风格。
Style
public void removeStyle(String nm)
null样式。
nm - 要删除的样式的名称
public void setLogicalStyle(Style s)
s - 分配给
s的逻辑风格,或没有风格的
null
public Style getLogicalStyle()
null 。
Style
public AttributeSet getCharacterAttributes()
null ,或
null 。
null
public void setCharacterAttributes(AttributeSet attr, boolean replace)
attr - 属性
replace - 如果为true,则先替换现有属性
public AttributeSet getParagraphAttributes()
null如果没有)。
public void setParagraphAttributes(AttributeSet attr, boolean replace)
attr - 非
null属性
replace - 如果为true,请先替换现有属性
public MutableAttributeSet getInputAttributes()
protected final StyledEditorKit getStyledEditorKit()
protected EditorKit createDefaultEditorKit()
EditorKit 。
这是实现返回javax.swing.text.StyledEditorKit 。
createDefaultEditorKit在
JEditorPane
public final void setEditorKit(EditorKit kit)
setEditorKit在
JEditorPane
kit - 所需的编辑器行为
IllegalArgumentException - 如果套件不是
StyledEditorKit
JEditorPane.getEditorKit()
protected String paramString()
JTextPane的字符串表示JTextPane 。
该方法仅用于调试目的,并且返回的字符串的内容和格式可能因实现而异。
返回的字符串可能为空,但可能不是null 。
paramString在
JEditorPane
JTextPane的字符串表示
JTextPane
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.