- 所有已实现的接口:
ImageObserver,MenuContainer,Serializable,Accessible,Scrollable
- 已知子类:
JTextPane
该组件使用 EditorKit 的实现来完成其行为。它有效地转变为适合其所提供内容类型的文本编辑器。编辑器在任何给定时间绑定到的内容类型由当前安装的 EditorKit 确定。如果内容设置为新 URL,则其类型用于确定应该用于加载内容的EditorKit。
默认情况下,已知以下类型的内容:
- 文本/纯文本
-
纯文本,默认情况下无法识别给定的类型。本例中使用的工具包是
DefaultEditorKit的扩展,可生成包装的纯文本视图。 - 文本/html
-
HTML 文本。本例中使用的工具包是类
javax.swing.text.html.HTMLEditorKit,它提供 HTML 3.2 支持。 - text/rtf
-
RTF 文本。本例中使用的工具包是类
javax.swing.text.rtf.RTFEditorKit,它提供对富文本格式的有限支持。
有几种方法可以将内容加载到该组件中。
setText方法可用于从字符串初始化组件。在这种情况下,当前的EditorKit将被使用,并且内容类型应该是这种类型。read方法可用于从Reader初始化组件。请注意,如果内容类型是 HTML,除非使用 <base> 标记或设置HTMLDocument上的 Base 属性,否则无法解析相对引用(例如图像之类的内容)。在这种情况下,当前的EditorKit将被使用,并且内容类型应该是这种类型。setPage方法可用于从 URL 初始化组件。在这种情况下,将根据 URL 确定内容类型,并设置该内容类型的注册EditorKit。
某些类型的内容可以通过生成超链接事件来提供超链接支持。如果 JEditorPane 是 not editable(已调用 JEditorPane.setEditable(false);),HTML EditorKit 将生成超链接事件。如果文档中嵌入了 HTML 框架,典型的响应将是更改当前文档的一部分。下面的代码片段是一个可能的超链接监听器实现,它专门处理 HTML 框架事件,并简单地显示任何其他激活的超链接。
class Hyperactive implements HyperlinkListener {
public void hyperlinkUpdate(HyperlinkEvent e) {
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
JEditorPane pane = (JEditorPane) e.getSource();
if (e instanceof HTMLFrameHyperlinkEvent) {
HTMLFrameHyperlinkEvent evt = (HTMLFrameHyperlinkEvent)e;
HTMLDocument doc = (HTMLDocument)pane.getDocument();
doc.processHTMLFrameHyperlinkEvent(evt);
} else {
try {
pane.setPage(e.getURL());
} catch (Throwable t) {
t.printStackTrace();
}
}
}
}
}
有关自定义方式的信息文本/html呈现请参阅 W3C_LENGTH_UNITS 和 HONOR_DISPLAY_PROPERTIES
某些文档中的文化相关信息是通过称为字符编码的机制处理的。字符编码是字符集成员(字母、表意文字、数字、符号或控制函数)到特定数字代码值的明确映射。它表示文件的存储方式。示例字符编码有 ISO-8859-1、ISO-8859-5、Shift-jis、Euc-jp 和 UTF-8。当文件传递给用户代理 (JEditorPane) 时,它被转换为文档字符集(ISO-10646 又名 Unicode)。
有多种方法可以使 JEditorPane 发生字符集映射。
- 一种方法是将字符集指定为 MIME 类型的参数。这将通过调用
setContentType方法来建立。如果内容是通过setPage方法加载的,则内容类型将根据 URL 的规范进行设置。如果文件是直接加载的,则内容类型应该在加载之前设置好。 - 可以指定字符集的另一种方法是在文档本身中。这需要在确定所需的字符集之前阅读文档。为了处理这个问题,预计
EditorKit.read 操作会抛出一个ChangedCharSetException,它会被捕获。然后使用使用ChangedCharSetException(即IOException)中指定的字符集的新阅读器重新开始读取。
- 换行符
- 有关如何处理换行符的讨论,请参阅 DefaultEditorKit。
Warning: Swing 不是线程安全的。有关详细信息,请参阅 Swing 的线程策略。
Warning: 此类的序列化对象将与未来的 Swing 版本不兼容。当前的序列化支持适用于运行相同版本 Swing 的应用程序之间的短期存储或 RMI。从 1.4 开始,对所有 JavaBeans 的长期存储的支持已添加到 java.beans 包中。请参阅 XMLEncoder 。
- 自从:
- 1.2
-
内部类总结
内部类修饰符和类型类描述protected class此类实现了对JEditorPane类的辅助功能支持。protected class此类为AccessibleHypertext提供支持,并用于安装在此JEditorPane中的EditorKit是HTMLEditorKit的实例的实例。protected classAccessibleJEditorPaneHTML.getAccessibleText返回的内容。在类 javax.swing.text.JTextComponent 中声明的嵌套类/接口
JTextComponent.AccessibleJTextComponent, JTextComponent.DropLocation, JTextComponent.KeyBinding在类 javax.swing.JComponent 中声明的嵌套类/接口
JComponent.AccessibleJComponent在类 java.awt.Container 中声明的嵌套类/接口
Container.AccessibleAWTContainer -
字段摘要
字段修饰符和类型Field描述static final String如果样式文本中未指定字体或前景色,则用于指示是否使用组件的默认字体和前景色的客户端属性键。static final String用于指示 符合 w3c 长度单位是否用于 html 呈现的客户端属性的键。在类 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 -
构造方法总结
构造方法构造方法描述创建一个新的JEditorPane。JEditorPane(String url) 基于包含 URL 规范的字符串创建JEditorPane。JEditorPane(String type, String text) 创建一个已初始化为给定文本的JEditorPane。JEditorPane(URL initialPage) 根据指定的输入 URL 创建一个JEditorPane。 -
方法总结
修饰符和类型方法描述voidaddHyperlinkListener(HyperlinkListener listener) 添加一个超链接监听以通知任何更改,例如当选择并输入链接时。protected EditorKit为首次创建组件时创建默认编辑器工具包 (PlainEditorKit)。static EditorKit从编辑器工具包的默认注册表中为给定类型创建一个处理程序。void通知所有已注册对此事件类型的通知感兴趣的监听。获取与此 JEditorPane 关联的 AccessibleContext。final String获取此编辑器当前设置为处理的内容类型。获取当前安装的用于处理内容的工具包。static String返回当前注册的type类型的EditorKit类名。获取编辑器工具包以用于给定类型的内容。返回使用 addHyperlinkListener() 添加到此 JEditorPane 的所有HyperLinkListener的数组。getPage()获取当前显示的 URL。返回JEditorPane的首选大小。boolean如果视口应始终强制此Scrollable的高度与视口的高度匹配,则返回 true。boolean如果视口应始终强制此Scrollable的宽度与视口的宽度匹配,则返回 true。protected InputStream获取给定 URL 的流,该流将由setPage方法加载。getText()根据此编辑器的内容类型返回此TextComponent中包含的文本。获取 UI 的类 ID。protected String返回此JEditorPane的字符串表示形式voidread(InputStream in, Object desc) 此方法从流初始化。static voidregisterEditorKitForContentType(String type, String classname) 建立type到classname的默认绑定。static voidregisterEditorKitForContentType(String type, String classname, ClassLoader loader) 建立type到classname的默认绑定。voidremoveHyperlinkListener(HyperlinkListener listener) 删除超链接监听。voidreplaceSelection(String content) 用给定字符串表示的新内容替换当前选择的内容。voidscrollToReference(String reference) 将视图滚动到给定的引用位置(即URL.getRef方法为正在显示的 URL 返回的值)。final voidsetContentType(String type) 设置此编辑器处理的内容类型。voidsetEditorKit(EditorKit kit) 设置当前安装的用于处理内容的工具包。voidsetEditorKitForContentType(String type, EditorKit k) 直接设置编辑器工具包以用于给定类型。void设置当前显示的 URL。void设置当前显示的 URL。void将此TextComponent的文本设置为指定的内容,该内容应采用此编辑器的内容类型的格式。在类 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, setDocument, 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
-
字段详细信息
-
W3C_LENGTH_UNITS
- 自从:
- 1.5
- 参见:
-
HONOR_DISPLAY_PROPERTIES
如果样式文本中未指定字体或前景色,则用于指示是否使用组件的默认字体和前景色的客户端属性键。默认值因外观而异;要启用它,请将具有此名称的客户端
property设置为Boolean.TRUE。- 自从:
- 1.5
- 参见:
-
-
构造方法详细信息
-
JEditorPane
public JEditorPane()创建一个新的JEditorPane。文档模型设置为null。 -
JEditorPane
根据指定的输入 URL 创建一个JEditorPane。- 参数:
initialPage- 网址- 抛出:
IOException- 如果 URL 为null或无法访问
-
JEditorPane
基于包含 URL 规范的字符串创建JEditorPane。- 参数:
url- 网址- 抛出:
IOException- 如果 URL 为null或无法访问
-
JEditorPane
创建一个已初始化为给定文本的JEditorPane。这是调用setContentType和setText方法的便捷构造函数。- 参数:
type- 给定文本的 mime 类型text- 用于初始化的文本;可能是null- 抛出:
NullPointerException- 如果type参数是null
-
-
方法详情
-
addHyperlinkListener
添加一个超链接监听以通知任何更改,例如当选择并输入链接时。- 参数:
listener- 听众
-
removeHyperlinkListener
删除超链接监听。- 参数:
listener- 听众
-
getHyperlinkListeners
返回使用 addHyperlinkListener() 添加到此 JEditorPane 的所有HyperLinkListener的数组。- 返回:
-
添加所有
HyperLinkListeners,如果没有添加任何监听器,则为空数组 - 自从:
- 1.4
-
fireHyperlinkUpdate
通知所有已注册对此事件类型的通知感兴趣的监听器。如果支持超链接的内容类型当前处于活动状态并且有链接活动,则通常由当前安装的EditorKit调用。监听器列表从最后到最先处理。- 参数:
e- 事件- 参见:
-
setPage
@BeanProperty (expert =true, description ="the URL used to set content") public void setPage(URL page) throws IOException 设置当前显示的 URL。窗格的内容类型已设置,如果窗格的编辑器工具包是非null,则会创建一个新的默认文档并将 URL 读入其中。如果 URL 包含引用位置,则将通过调用scrollToReference方法滚动到该位置。如果所需的 URL 是当前显示的 URL,则不会重新加载文档。要强制重新加载文档,必须清除文档的流描述属性。下面的代码显示了如何做到这一点:Document doc = jEditorPane.getDocument(); doc.putProperty(Document.StreamDescriptionProperty, null);
如果所需的 URL 不是当前显示的 URL,则调用getStream方法让子类控制所提供的流。这可能会同步或异步加载,具体取决于
EditorKit返回的文档。如果Document的类型为AbstractDocument且AbstractDocument.getAsynchronousLoadPriority返回的值大于或等于零,则页面将使用该优先级在单独的线程上加载。如果文档是同步加载的,它会在通过调用
setDocument被安装到编辑器之前用流填充,它被绑定并将触发属性更改事件。如果抛出IOException,则部分加载的文档将被丢弃,并且不会触发文档或页面属性更改事件。如果文档被成功加载和安装,UI 将为其构建一个视图,然后在必要时滚动该视图,然后将触发页面属性更改事件。如果文档是异步加载的,文档将通过调用
setDocument立即安装到编辑器中,这将触发一个文档属性更改事件,然后将创建一个线程,该线程将开始进行实际加载。在这种情况下,页面属性更改事件不会通过调用此方法直接触发,而是在执行加载的线程完成时触发。它还将在事件派发线程上被触发。由于调用线程不能在其他线程失败的情况下抛出IOException,因此无论加载是否成功,页面属性更改事件都将在其他线程完成时触发。- 参数:
page- 页面的 URL- 抛出:
IOException- 对于null或无效的页面规范,或来自正在读取的流的异常- 参见:
-
read
此方法从流初始化。如果套件设置为HTMLEditorKit类型,并且desc参数是HTMLDocument,则它调用HTMLEditorKit来启动读取。否则它会调用超类方法将模型加载为纯文本。- 参数:
in- 从中读取的流desc- 描述流的对象- 抛出:
IOException- 由用于初始化的流抛出- 参见:
-
getStream
获取给定 URL 的流,该流将由setPage方法加载。默认情况下,这只是打开 URL 并返回流。这可以重新实现以执行有用的操作,例如从缓存中获取流、监视流的进度等。此方法预计会产生建立内容类型的副作用,因此设置适当的
EditorKit以用于加载流。如果此流是一个 http 连接,将遵循重定向并将生成的 URL 设置为
Document.StreamDescriptionProperty,以便可以正确解析相对 URL。- 参数:
page- 页面的 URL- 返回:
- 即将加载的 URL 流
- 抛出:
IOException- 如果出现 I/O 问题
-
scrollToReference
将视图滚动到给定的引用位置(即URL.getRef方法为正在显示的 URL 返回的值)。默认情况下,此方法只知道如何在 HTMLDocument 中定位引用。该实现调用scrollRectToVisible方法来完成实际的滚动。如果 HTML 以外的文档类型需要滚动到参考位置,则应重新实现此方法。如果组件不可见,此方法将无效。- 参数:
reference- 要滚动到的命名位置
-
getPage
获取当前显示的 URL。如果在创建文档时未指定 URL,这将返回null并且不会解析相对 URL。- 返回:
-
URL,如果没有则为
null
-
setPage
设置当前显示的 URL。- 参数:
url- 显示的 URL- 抛出:
IOException- 对于null或无效的 URL 规范
-
getUIClassID
获取 UI 的类 ID。- 重写:
getUIClassID在类JComponent中- 返回:
- 字符串“EditorPaneUI”
- 参见:
-
createDefaultEditorKit
为首次创建组件时创建默认编辑器工具包 (PlainEditorKit)。- 返回:
- 编辑器套件
-
getEditorKit
获取当前安装的用于处理内容的工具包。如有必要,createDefaultEditorKit将被调用以设置默认值。- 返回:
- 编辑器套件
-
getContentType
获取此编辑器当前设置为处理的内容类型。这被定义为与当前安装的EditorKit关联的类型。- 返回:
-
内容类型,
null如果没有设置编辑器工具包
-
setContentType
@BeanProperty (bound =false, description ="the type of content") public final void setContentType(String type) 设置此编辑器处理的内容类型。这将调用getEditorKitForContentType,如果可以成功找到编辑器工具包,则调用setEditorKit。这主要是一种方便的方法,可以用作直接调用setEditorKit的替代方法。如果将字符集定义指定为内容类型规范的参数,则在使用关联的
EditorKit加载输入流时将使用它。例如,如果类型指定为text/html; charset=EUC-JP,将使用为text/html注册的EditorKit加载内容,提供给EditorKit以将 unicode 加载到文档中的阅读器将使用EUC-JP字符集转换为 unicode。如果无法识别类型,将使用为纯文本注册的EditorKittext/plain加载内容。- 参数:
type- 用于内容编辑支持的非nullmime 类型- 抛出:
NullPointerException- 如果type参数是null- 参见:
-
setEditorKit
@BeanProperty (expert =true, description ="the currently installed kit for handling content") public void setEditorKit(EditorKit kit) 设置当前安装的用于处理内容的工具包。这是建立编辑器内容类型的绑定属性。首先卸载任何旧套件,然后如果套件是非null,则安装新套件,并为其创建默认文档。当调用setEditorKit时,总是会触发PropertyChange事件(“editorKit”)。NOTE: This has the side effect of changing the model, because the
EditorKitis the source of how a particular type of content is modeled. This method will causesetDocumentto be called on behalf of the caller to ensure integrity of the internal state.- 参数:
kit- 所需的编辑器行为- 参见:
-
getEditorKitForContentType
获取编辑器工具包以用于给定类型的内容。当请求的类型与当前安装的类型不匹配时调用。如果组件没有为给定类型注册EditorKit,它将尝试从默认的EditorKit注册表创建一个EditorKit。如果失败,则使用PlainEditorKit假设所有文本文档都可以表示为纯文本。可以重新实现此方法以使用其他类型的注册表。例如,这可以重新实现以使用 Java Activation Framework。
- 参数:
type- 非null内容类型- 返回:
- 编辑器套件
-
setEditorKitForContentType
直接设置编辑器工具包以用于给定类型。外观实现可能会使用它与createEditorKitForContentType一起为具有外观偏差的内容类型安装处理程序。- 参数:
type- 非null内容类型k- 要设置的编辑器工具包
-
replaceSelection
用给定字符串表示的新内容替换当前选择的内容。如果没有选择,这相当于给定文本的插入。如果没有替换文本(即内容字符串为空或null),这相当于删除当前选择。替换文本将具有当前为输入定义的属性。如果组件不可编辑,发出哔哔声并返回。- 重写:
replaceSelection在类JTextComponent中- 参数:
content- 用来替换选择的内容。这个值可以是null
-
createEditorKitForContentType
从编辑器工具包的默认注册表中为给定类型创建一个处理程序。如有必要,将创建注册表。如果尚未加载已注册的类,则会尝试动态加载给定类型的套件原型。如果该类型使用ClassLoader注册,则该ClassLoader将用于加载原型。如果没有注册ClassLoader,Class.forName将用于加载原型。一旦原型
EditorKit实例被成功定位,它就会被克隆并返回克隆。- 参数:
type- 内容类型- 返回:
-
编辑器工具包,如果没有为给定类型注册任何内容,则为
null
-
registerEditorKitForContentType
建立type到classname的默认绑定。该类将在实际需要时动态加载,并且可以在尝试使用之前安全地更改以避免加载不需要的类。使用此方法注册时,原型EditorKit将与Class.forName一起加载。- 参数:
type- 非null内容类型classname- 稍后加载的类
-
registerEditorKitForContentType
public static void registerEditorKitForContentType(String type, String classname, ClassLoader loader) 建立type到classname的默认绑定。该类将在实际需要时使用给定的ClassLoader动态加载,并且可以在尝试使用之前安全地更改以避免加载不需要的类。- 参数:
type- 非null内容类型classname- 稍后加载的类loader- 用于加载名称的ClassLoader
-
getEditorKitClassNameForContentType
返回当前注册的type类型的EditorKit类名。- 参数:
type- 非null内容类型- 返回:
-
一个
String包含type的EditorKit类名 - 自从:
- 1.3
-
getPreferredSize
返回JEditorPane的首选大小。JEditorPane的首选大小与超类的首选大小略有不同。如果视口的大小变得小于组件的最小大小,跟踪宽度或高度的可滚动定义将变为 false。默认视口布局将提供首选大小,这在可滚动跟踪的情况下是不需要的。在这种情况下,normal 首选大小将调整为最小大小。这允许诸如 HTML 表格之类的东西缩小到它们的最小尺寸,然后以它们的最小尺寸进行布局,拒绝进一步缩小。- 重写:
getPreferredSize在类JComponent中- 返回:
-
包含首选尺寸的
Dimension - 参见:
-
setText
@BeanProperty (bound =false, description ="the text of this component") public void setText(String t) 将此TextComponent的文本设置为指定的内容,该内容应采用此编辑器的内容类型的格式。例如,如果类型设置为text/html,则应根据 HTML 指定字符串。这是为了删除当前文档的内容,并通过使用当前的
EditorKit解析给定的字符串来替换它们。这通过不更改模型来提供超类的语义,同时支持当前在此组件上设置的内容类型。假设前面的内容相对较小,并且前面的内容没有副作用。这两个假设都可能被违反并导致不良结果。为避免这种情况,请创建一个新文档getEditorKit().createDefaultDocument()并将现有的Document替换为新文档。然后您可以放心,之前的Document不会有任何挥之不去的状态。- 保留现有模型意味着旧视图将被拆除,并创建一个新视图,其中替换文档将避免拆除旧视图。
- 某些格式(如 HTML)可以将某些东西添加到文档中,从而影响未来的内容。 HTML 可以嵌入样式信息,这些信息会意外地影响下一个安装的内容。
使用字符串加载此组件的另一种方法是创建一个 StringReader 并调用 read 方法。在这种情况下,模型将在用字符串内容初始化后被替换。
- 重写:
setText在类JTextComponent中- 参数:
t- 要设置的新文本;如果null旧文本将被删除- 参见:
-
getText
根据此编辑器的内容类型返回此TextComponent中包含的文本。如果在尝试检索文本时抛出异常,将返回null。这是为了调用JTextComponent.write和StringWriter而实现的。- 重写:
getText在类JTextComponent中- 返回:
- 文本
- 参见:
-
getScrollableTracksViewportWidth
如果视口应始终强制此Scrollable的宽度与视口的宽度匹配,则返回 true。- 指定者:
getScrollableTracksViewportWidth在接口Scrollable中- 重写:
getScrollableTracksViewportWidth在类JTextComponent中- 返回:
- 如果视口应该强制 Scrollables 宽度匹配它自己的宽度,则为 true,否则为 false
-
getScrollableTracksViewportHeight
如果视口应始终强制此Scrollable的高度与视口的高度匹配,则返回 true。- 指定者:
getScrollableTracksViewportHeight在接口Scrollable中- 重写:
getScrollableTracksViewportHeight在类JTextComponent中- 返回:
-
如果视口应强制
Scrollable的高度与其自身的高度匹配,则为 true,否则为 false
-
paramString
返回此JEditorPane的字符串表示形式。此方法仅用于调试目的,返回字符串的内容和格式可能因实现而异。返回的字符串可能为空,但可能不是null。- 重写:
paramString在类JTextComponent中- 返回:
-
这个
JEditorPane的字符串表示
-
getAccessibleContext
获取与此 JEditorPane 关联的 AccessibleContext。对于编辑器窗格,AccessibleContext 采用 AccessibleJEditorPane 的形式。如有必要,将创建一个新的 AccessibleJEditorPane 实例。- 指定者:
getAccessibleContext在接口Accessible中- 重写:
getAccessibleContext在类JTextComponent中- 返回:
- 作为此 JEditorPane 的 AccessibleContext 的 AccessibleJEditorPane
-