- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- javax.swing.text.JTextComponent
-
- javax.swing.JEditorPane
-
- 实现的所有接口
-
ImageObserver,MenuContainer,Serializable,Accessible,Scrollable
- 已知直接子类:
-
JTextPane
@JavaBean(defaultProperty="UIClassID", description="A text component to edit various types of content.") public class JEditorPane extends JTextComponent
用于编辑各种内容的文本组件。 您可以在Using Text Components (Java教程的一个部分)中找到使用编辑器窗格的操作方法信息和示例。该组件使用
EditorKit的实现来完成其行为。 它有效地变形为适当类型的文本编辑器,用于给出它的内容。 编辑器在任何给定时间绑定的内容类型由当前安装的EditorKit确定。 如果内容设置为新URL,则其类型用于确定应用于加载内容的EditorKit。默认情况下,已知以下类型的内容:
- 纯文本/
-
纯文本,默认情况下,无法识别给定的类型。
在这种情况下使用的工具包是
DefaultEditorKit的扩展,它生成一个包装的纯文本视图。 - text / html的
-
HTML文字。
在这种情况下使用的工具包是
javax.swing.text.html.HTMLEditorKit类,它提供HTML 3.2支持。 - 文/ RTF
-
RTF文本。
在这种情况下使用的工具包是
javax.swing.text.rtf.RTFEditorKit类,它提供了对RTF格式的有限支持。
有几种方法可以将内容加载到此组件中。
-
setText方法可用于从字符串初始化组件。 在这种情况下,将使用当前的EditorKit,并且内容类型应该是这种类型。 -
read方法可用于从Reader初始化组件。 请注意,如果内容类型为HTML,则除非使用<base>标记或设置了HTMLDocument上的Base属性,否则无法解析相对引用(例如像图像之类的内容)。 在这种情况下,将使用当前的EditorKit,并且预期内容类型将属于此类型。 -
setPage方法可用于从URL初始化组件。 在这种情况下,将从URL确定内容类型,并且将设置该内容类型的注册EditorKit。
某些内容可以通过生成超链接事件来提供超链接支持。 该HTML
EditorKit会生成超链接事件如果JEditorPane是不可编辑的 (JEditorPane.setEditable(false);被调用)。 如果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(); } } } } }有关自定义text / 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,它将被捕获。 然后使用新的Reader重新启动读取,该Reader使用ChangedCharSetException(即IOException)中指定的字符集。
- 换行
- 有关如何处理换行的讨论,请参阅DefaultEditorKit 。
警告: Swing不是线程安全的。 有关更多信息,请参阅Swing's Threading Policy 。
警告:此类的序列化对象与以后的Swing版本不兼容。 当前的序列化支持适用于运行相同版本Swing的应用程序之间的短期存储或RMI。 从1.4开始,
java.beans软件包中添加了对所有JavaBeansjava.beans长期存储的支持。 请参阅XMLEncoder。- 从以下版本开始:
- 1.2
- 另请参见:
- Serialized Form
-
-
嵌套类汇总
嵌套类 变量和类型 类 描述 protected classJEditorPane.AccessibleJEditorPane此类实现JEditorPane类的可访问性支持。protected classJEditorPane.AccessibleJEditorPaneHTML此类提供对AccessibleHypertext支持,用于此EditorKit安装的JEditorPane是JEditorPane的实例的HTMLEditorKit。protected classJEditorPane.JEditorPaneAccessibleHypertextSupportAccessibleJEditorPaneHTML.getAccessibleText返回了AccessibleJEditorPaneHTML.getAccessibleText。-
嵌套类/接口声明在类 javax.swing.text.JTextComponent
JTextComponent.AccessibleJTextComponent, JTextComponent.DropLocation, JTextComponent.KeyBinding
-
嵌套类/接口声明在类 javax.swing.JComponent
JComponent.AccessibleJComponent
-
嵌套类/接口声明在类 java.awt.Container
Container.AccessibleAWTContainer
-
-
字段汇总
字段 变量和类型 字段 描述 static StringHONOR_DISPLAY_PROPERTIES客户端属性的键,用于指示在样式化文本中未指定字体或前景颜色时是否使用组件的默认字体和前景色。static StringW3C_LENGTH_UNITS客户端属性的键,用于指示 w3c compliant长度单位是否用于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
-
Fields declared in interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
-
-
构造方法摘要
构造方法 构造器 描述 JEditorPane()创建一个新的JEditorPane。JEditorPane(String url)根据包含URL规范的字符串创建JEditorPane。JEditorPane(String type, String text)创建已初始化为给定文本的JEditorPane。JEditorPane(URL initialPage)根据指定的URL输入创建JEditorPane。
-
方法摘要
所有方法 静态方法 实例方法 具体的方法 变量和类型 方法 描述 voidaddHyperlinkListener(HyperlinkListener listener)添加超链接侦听器以通知任何更改,例如选择并输入链接时。protected EditorKitcreateDefaultEditorKit()为首次创建组件时创建默认编辑器工具包(PlainEditorKit)。static EditorKitcreateEditorKitForContentType(String type)从编辑器工具包的默认注册表创建给定类型的处理程序。voidfireHyperlinkUpdate(HyperlinkEvent e)通知所有已注册对此事件类型的通知感兴趣的听众。AccessibleContextgetAccessibleContext()获取与此JEditorPane关联的AccessibleContext。StringgetContentType()获取此编辑器当前设置要处理的内容类型。EditorKitgetEditorKit()获取当前安装的工具包以处理内容。static StringgetEditorKitClassNameForContentType(String type)返回类型type的当前注册的EditorKit类名。EditorKitgetEditorKitForContentType(String type)获取编辑器工具包以用于给定类型的内容。HyperlinkListener[]getHyperlinkListeners()返回使用addHyperlinkListener()添加到此JEditorPane的所有HyperLinkListener的数组。URLgetPage()获取当前显示的URL。DimensiongetPreferredSize()返回JEditorPane的首选大小。booleangetScrollableTracksViewportHeight()如果视口应始终强制此Scrollable的高度与视口的高度匹配,则返回true。booleangetScrollableTracksViewportWidth()如果视口应始终强制此Scrollable的宽度与视口的宽度匹配,则返回true。protected InputStreamgetStream(URL page)获取给定URL的流,该URL将由setPage方法加载。StringgetText()根据此编辑器的内容类型返回此TextComponent中包含的文本。StringgetUIClassID()获取UI的类ID。protected StringparamString()返回此JEditorPane的字符串表示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的URL.getRef方法返回的值)。voidsetContentType(String type)设置此编辑器处理的内容类型。voidsetEditorKit(EditorKit kit)设置当前安装的用于处理内容的工具包。voidsetEditorKitForContentType(String type, EditorKit k)直接设置编辑器工具包以用于给定类型。voidsetPage(String url)设置当前显示的URL。voidsetPage(URL page)设置当前显示的URL。voidsetText(String t)将此TextComponent的文本设置为指定的内容,该内容应采用此编辑器的内容类型的格式。-
声明方法的类 javax.swing.text.JTextComponent
addCaretListener, addKeymap, copy, cut, fireCaretUpdate, getActions, getCaret, getCaretColor, getCaretListeners, getCaretPosition, getDisabledTextColor, getDocument, getDragEnabled, getDropLocation, getDropMode, getFocusAccelerator, getHighlighter, 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, 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, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, 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
public static final String W3C_LENGTH_UNITS
客户端属性的键,用于指示w3c compliant长度单位是否用于html呈现。默认情况下,此功能未启用; 启用它将客户端
property设置为Boolean.TRUE。- 从以下版本开始:
- 1.5
- 另请参见:
- 常数字段值
-
-
构造方法详细信息
-
JEditorPane
public JEditorPane()
创建一个新的JEditorPane。 文档模型设置为null。
-
JEditorPane
public JEditorPane(URL initialPage) throws IOException
根据指定的URL输入创建JEditorPane。- 参数
-
initialPage- URL - 异常
-
IOException- 如果URL是null或无法访问
-
JEditorPane
public JEditorPane(String url) throws IOException
根据包含URL规范的字符串创建JEditorPane。- 参数
-
url- URL - 异常
-
IOException- 如果URL是null或无法访问
-
JEditorPane
public JEditorPane(String type, String text)
创建已初始化为给定文本的JEditorPane。 这是一个方便的构造函数,它调用setContentType和setText方法。- 参数
-
type- 给定文本的mime类型 -
text- 要初始化的文本; 可能是null - 异常
-
NullPointerException- 如果type参数为null
-
-
方法详细信息
-
addHyperlinkListener
public void addHyperlinkListener(HyperlinkListener listener)
添加超链接侦听器以通知任何更改,例如选择并输入链接时。- 参数
-
listener- 听众
-
removeHyperlinkListener
public void removeHyperlinkListener(HyperlinkListener listener)
删除超链接侦听器。- 参数
-
listener- 听众
-
getHyperlinkListeners
@BeanProperty(bound=false) public HyperlinkListener[] getHyperlinkListeners()
返回使用addHyperlinkListener()添加到此JEditorPane的所有HyperLinkListener的数组。- 结果
-
如果没有添加任何侦听器,则添加所有
HyperLinkListener或空数组 - 从以下版本开始:
- 1.4
-
fireHyperlinkUpdate
public void fireHyperlinkUpdate(HyperlinkEvent e)
通知所有已注册对此事件类型的通知感兴趣的听众。 如果支持超链接的内容类型当前处于活动状态并且存在带链接的活动,则通常由当前安装的EditorKit调用此方法。 侦听器列表从最后到第一个处理。- 参数
-
e- 活动 - 另请参见:
-
EventListenerList
-
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或无效页面规范,或正在读取的流中的异常 - 另请参见:
-
getPage()
-
read
public void read(InputStream in, Object desc) throws IOException
此方法从流初始化。 如果套件设置为HTMLEditorKit类型,并且desc参数为HTMLDocument,则它将调用HTMLEditorKit以启动读取。 否则,它调用超类方法,该方法将模型加载为纯文本。- 参数
-
in- 要读取的流 -
desc- 描述流的对象 - 异常
-
IOException- 由用于初始化的流抛出 - 另请参见:
-
JTextComponent.read(java.io.Reader, java.lang.Object),JTextComponent.setDocument(javax.swing.text.Document)
-
getStream
protected InputStream getStream(URL page) throws IOException
获取给定URL的流,该URL将由setPage方法加载。 默认情况下,这只会打开URL并返回流。 这可以重新实现以执行有用的操作,例如从缓存中获取流,监视流的进度等。预计此方法具有建立内容类型的副作用,因此设置适当的
EditorKit以用于加载流。如果此流是http连接,则将遵循重定向,并将生成的URL设置为
Document.StreamDescriptionProperty以便可以正确解析相对URL。- 参数
-
page- 网页的URL - 结果
- 即将加载的URL的流
- 异常
-
IOException- 如果发生I / O问题
-
scrollToReference
public void scrollToReference(String reference)
将视图滚动到给定的引用位置(即URL.getRef方法为显示的URL返回的值)。 默认情况下,此方法仅知道如何在HTMLDocument中查找引用。 该实现调用scrollRectToVisible方法来完成实际滚动。 如果HTML以外的文档类型需要滚动到引用位置,则应重新实现此方法。 如果组件不可见,则此方法无效。- 参数
-
reference- 要滚动到的指定位置
-
getPage
public URL getPage()
获取当前显示的URL。 如果在创建文档时未指定URL,则返回null,并且不会解析相对URL。- 结果
-
URL,如果没有,
null
-
setPage
public void setPage(String url) throws IOException
设置当前显示的URL。- 参数
-
url- 显示的URL - 异常
-
IOException- 适用于null或无效的URL规范
-
getUIClassID
@BeanProperty(bound=false) public String getUIClassID()
获取UI的类ID。- 重写:
-
getUIClassID类JComponent - 结果
- 字符串“EditorPaneUI”
- 另请参见:
-
JComponent.getUIClassID(),UIDefaults.getUI(javax.swing.JComponent)
-
createDefaultEditorKit
protected EditorKit createDefaultEditorKit()
首次创建组件时,创建默认编辑器工具包(PlainEditorKit)。- 结果
- 编辑工具包
-
getEditorKit
public EditorKit getEditorKit()
获取当前安装的工具包以处理内容。 如有必要,调用createDefaultEditorKit设置默认值。- 结果
- 编辑工具包
-
getContentType
public final String getContentType()
获取此编辑器当前设置要处理的内容类型。 这被定义为与当前安装的EditorKit相关联的类型。- 结果
-
内容类型,如果没有设置编辑器套件,
null
-
setContentType
@BeanProperty(bound=false, description="the type of content") public final void setContentType(String type)
设置此编辑器处理的内容类型。 这就要求getEditorKitForContentType,然后setEditorKit如果一个编辑器工具包可以被成功定位。 这主要是方便的方法,可以作为直接调用setEditorKit的替代方法。如果将charset定义指定为内容类型规范的参数,则在使用关联的
EditorKit加载输入流时将使用该EditorKit。 例如,如果类型指定为text/html; charset=EUC-JP,则将使用为EditorKit注册的text/html加载内容,并且提供给EditorKit以将unicode加载到文档中的Reader将使用EUC-JP字符集转换为unicode。 如果类型无法识别,内容将采用加载EditorKit纯文本注册,text/plain。- 参数
-
type- 非nullmime类型,用于内容编辑支持 - 异常
-
NullPointerException- 如果type参数为null - 另请参见:
-
getContentType()
-
setEditorKit
@BeanProperty(expert=true, description="the currently installed kit for handling content") public void setEditorKit(EditorKit kit)
设置当前安装的用于处理内容的工具包。 这是建立编辑器内容类型的绑定属性。 首先卸载任何旧套件,然后如果套件为非null,则安装新套件,并为其创建默认文档。 一个PropertyChange当事件(“的EditorKit”)是始终点火setEditorKit被调用。注意:这具有更改模型的
EditorKit,因为EditorKit是特定类型内容的建模方式的来源。 此方法将导致代表调用方调用setDocument以确保内部状态的完整性。- 参数
-
kit- 所需的编辑器行为 - 另请参见:
-
getEditorKit()
-
getEditorKitForContentType
public EditorKit getEditorKitForContentType(String type)
获取编辑器工具包以用于给定类型的内容。 当请求的类型与当前安装的类型不匹配时,将调用此方法。 如果组件不具有EditorKit注册给定类型,它会尝试创建一个EditorKit从默认EditorKit注册表。 如果失败,则假设所有文本文档都可以表示为纯文本,则使用PlainEditorKit。可以重新实现此方法以使用其他类型的注册表。 例如,可以重新实现这一点以使用Java Activation Framework。
- 参数
-
type- 非null内容类型 - 结果
- 编辑工具包
-
setEditorKitForContentType
public void setEditorKitForContentType(String type, EditorKit k)
直接设置编辑器工具包以用于给定类型。 外观实现可能会将此与createEditorKitForContentType结合使用,createEditorKitForContentType为具有外观偏差的内容类型安装处理程序。- 参数
-
type- 非null内容类型 -
k- 要设置的编辑器工具包
-
replaceSelection
public void replaceSelection(String content)
用当前字符串表示的新内容替换当前选定的内容。 如果没有选择,则相当于给定文本的插入。 如果没有替换文本(即内容字符串为空或null),则相当于删除当前选择。 替换文本将具有当前为输入定义的属性。 如果组件不可编辑,则发出蜂鸣声并返回。- 重写:
-
replaceSelection类JTextComponent - 参数
-
content- 要替换选择的内容。 该值可以是null
-
createEditorKitForContentType
public static EditorKit createEditorKitForContentType(String type)
从编辑器工具包的默认注册表创建给定类型的处理程序。 如有必要,将创建注册表。 如果尚未加载已注册的类,则尝试动态加载给定类型的套件原型。 如果类型已使用ClassLoader注册,则将使用该ClassLoader加载原型。 如果没有注册ClassLoader,将使用Class.forName加载原型。成功定位原型
EditorKit实例后,将对其进行克隆并返回克隆。- 参数
-
type- 内容类型 - 结果
-
编辑器工具包,或
null如果没有注册给定类型
-
registerEditorKitForContentType
public static void registerEditorKitForContentType(String type, String classname)
建立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
public static String getEditorKitClassNameForContentType(String type)
返回类型type的当前注册的EditorKit类名。- 参数
-
type- 非null内容类型 - 结果
-
String包含EditorKit类名称type - 从以下版本开始:
- 1.3
-
getPreferredSize
public Dimension getPreferredSize()
返回JEditorPane的首选大小。JEditorPane的首选大小与超类的首选大小略有不同。 如果视口的大小小于组件的最小大小,则跟踪宽度或高度的可滚动定义将变为false。 默认视口布局将给出首选大小,并且在可滚动跟踪的情况下不需要。 在这种情况下,将正常的优选尺寸调整到最小尺寸。 这允许HTML表格缩小到最小尺寸,然后以最小尺寸布局,拒绝进一步缩小。- 重写:
-
getPreferredSize类JComponent - 结果
-
a
Dimension包含首选大小 - 另请参见:
-
JComponent.setPreferredSize(java.awt.Dimension),ComponentUI
-
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()
-
getText
public String getText()
根据此编辑器的内容类型返回此TextComponent中包含的文本。 如果在尝试检索文本时抛出异常,将返回null。 实现此方法来调用JTextComponent.write与StringWriter。- 重写:
-
getText类JTextComponent - 结果
- 文本
- 另请参见:
-
setText(java.lang.String)
-
getScrollableTracksViewportWidth
@BeanProperty(bound=false) public boolean getScrollableTracksViewportWidth()
如果视口应始终强制此Scrollable的宽度与视口的宽度匹配,则返回true。- Specified by:
-
getScrollableTracksViewportWidth在接口Scrollable - 重写:
-
getScrollableTracksViewportWidth类JTextComponent - 结果
- 如果视口应强制Scrollables宽度与其自身匹配,则返回true,否则返回false
-
getScrollableTracksViewportHeight
@BeanProperty(bound=false) public boolean getScrollableTracksViewportHeight()
如果视口应始终强制此Scrollable的高度与视口的高度匹配,则返回true。- Specified by:
-
getScrollableTracksViewportHeight在界面Scrollable - 重写:
-
getScrollableTracksViewportHeight类JTextComponent - 结果
-
如果视口应强制
Scrollable的高度与其自身匹配,Scrollabletrue,否则为false
-
paramString
protected String paramString()
返回此JEditorPane的字符串表示JEditorPane。 此方法仅用于调试目的,返回字符串的内容和格式可能因实现而异。 返回的字符串可能为空,但可能不是null。- 重写:
-
paramString类JTextComponent - 结果
-
此
JEditorPane的字符串表示JEditorPane
-
getAccessibleContext
@BeanProperty(bound=false) public AccessibleContext getAccessibleContext()
获取与此JEditorPane关联的AccessibleContext。 对于编辑器窗格,AccessibleContext采用AccessibleJEditorPane的形式。 如有必要,将创建一个新的AccessibleJEditorPane实例。- Specified by:
-
getAccessibleContext在接口Accessible - 重写:
-
getAccessibleContext类JTextComponent - 结果
- 一个AccessibleJEditorPane,用作此JEditorPane的AccessibleContext
-
-