public class JEditorPane extends JTextComponent
该组件使用EditorKit的EditorKit来完成其行为。 它有效地转化为适当的文本编辑器,用于提供给他们的内容。 编辑器在任何给定时间绑定的内容类型由当前EditorKit EditorKit确定。 如果内容设置为新的URL,则其类型用于确定应用于加载内容的EditorKit 。
默认情况下,以下类型的内容是已知的:
DefaultEditorKit ,它生成一个包装的纯文本视图。
javax.swing.text.html.HTMLEditorKit 。
javax.swing.text.rtf.RTFEditorKit类,它提供了富文本格式的有限支持。
有多种方法可以将内容加载到此组件中。
setText方法可用于从字符串初始化组件。 在这种情况下,将使用当前的EditorKit ,并且内容类型将被预期为这种类型。 read方法可用于从Reader 。 请注意,如果内容类型为HTML,则无法解析相对引用(例如图像等),除非使用了<base>标签或设置了HTMLDocument的Base属性。 在这种情况下,将使用当前的EditorKit ,并且内容类型将被预期为这种类型。 setPage方法可用于从URL初始化组件。 在这种情况下,将从URL确定内容类型,并且将为该内容类型设置注册的EditorKit 。 某些内容可以通过生成超链接事件来提供超链接支持。 如果JEditorPane 不可编辑 ( 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 。
setContentType方法来建立。 如果内容由setPage方法加载,则内容类型将根据URL的规定进行设置。 它直接加载该文件,预期内容类型将在加载之前设置。 EditorKit操作会抛出一个ChangedCharSetException将被抓住。 然后用新的Reader读取读取,该Reader使用ChangedCharSetException (这是一个IOException )中指定的字符集。 警告: Swing不是线程安全的。 有关更多信息,请参阅Swing's Threading Policy 。
警告:此类的序列化对象与将来的Swing版本不兼容。 当前的序列化支持适用于运行相同版本的Swing的应用程序之间的短期存储或RMI。 从1.4开始,对所有JavaBeans的长期存储的支持已经添加到java.beans包中。 请参阅XMLEncoder 。
| Modifier and Type | Class and Description |
|---|---|
protected class |
JEditorPane.AccessibleJEditorPane
这个类实现了可访问性支持
JEditorPane类。
|
protected class |
JEditorPane.AccessibleJEditorPaneHTML
此类提供支持
AccessibleHypertext ,并且在当所使用
EditorKit安装在该
JEditorPane是的一个实例
HTMLEditorKit 。
|
protected class |
JEditorPane.JEditorPaneAccessibleHypertextSupport
AccessibleJEditorPaneHTML.getAccessibleText返回的
AccessibleJEditorPaneHTML.getAccessibleText 。
|
JTextComponent.AccessibleJTextComponent, JTextComponent.DropLocation, JTextComponent.KeyBindingJComponent.AccessibleJComponentContainer.AccessibleAWTContainerComponent.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy| Modifier and Type | Field and Description |
|---|---|
static String |
HONOR_DISPLAY_PROPERTIES
客户端属性的键用于指示如果在样式文本中未指定字体或前景颜色,则会使用来自组件的默认字体和前景颜色。
|
static String |
W3C_LENGTH_UNITS
用于指示是否将
w3c compliant长度单位用于html渲染的客户端属性的键。
|
DEFAULT_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 |
|---|
JEditorPane()
创建一个新的
JEditorPane 。
|
JEditorPane(String url)
创建一个
JEditorPane根据包含URL规范的字符串。
|
JEditorPane(String type, String text)
创建一个
JEditorPane已初始化为给定的文本。
|
JEditorPane(URL initialPage)
根据指定的URL创建
JEditorPane以进行输入。
|
| Modifier and Type | Method and Description |
|---|---|
void |
addHyperlinkListener(HyperlinkListener listener)
添加超链接侦听器以通知任何更改,例如选择并输入链接时。
|
protected EditorKit |
createDefaultEditorKit()
创建组件首次创建时的默认编辑器工具包(
PlainEditorKit )。
|
static EditorKit |
createEditorKitForContentType(String type)
从编辑器工具箱的默认注册表创建给定类型的处理程序。
|
void |
fireHyperlinkUpdate(HyperlinkEvent e)
通知所有在此事件类型上通知有兴趣的听众。
|
AccessibleContext |
getAccessibleContext()
获取与此JEditorPane关联的AccessibleContext。
|
String |
getContentType()
获取此编辑器当前设置处理的内容类型。
|
EditorKit |
getEditorKit()
获取当前安装的套件以处理内容。
|
static String |
getEditorKitClassNameForContentType(String type)
返回当前注册的
EditorKit类别名称,类型为
type 。
|
EditorKit |
getEditorKitForContentType(String type)
获取编辑器套件以用于给定类型的内容。
|
HyperlinkListener[] |
getHyperlinkListeners()
返回使用addHyperlinkListener()添加到此JEditorPane的所有
HyperLinkListener的数组。
|
URL |
getPage()
获取正在显示的当前URL。
|
Dimension |
getPreferredSize()
返回首选大小
JEditorPane 。
|
boolean |
getScrollableTracksViewportHeight()
如果视口总是强制此
Scrollable的高度与视口的高度相匹配,则返回true。
|
boolean |
getScrollableTracksViewportWidth()
如果视口总是强制此
Scrollable的宽度与视口的宽度相匹配,则返回true。
|
protected InputStream |
getStream(URL page)
获取给定URL的流,即将由
setPage方法加载。
|
String |
getText()
根据此编辑器的内容类型返回此
TextComponent中包含的文本。
|
String |
getUIClassID()
获取UI的类ID。
|
protected String |
paramString()
返回此
JEditorPane的字符串表示
JEditorPane 。
|
void |
read(InputStream in, Object desc)
此方法从流初始化。
|
static void |
registerEditorKitForContentType(String type, String classname)
建立默认的
type绑定到
classname 。
|
static void |
registerEditorKitForContentType(String type, String classname, ClassLoader loader)
建立的默认绑定
type到
classname 。
|
void |
removeHyperlinkListener(HyperlinkListener listener)
删除超链接侦听器。
|
void |
replaceSelection(String content)
用给定字符串表示的新内容替换当前所选内容。
|
void |
scrollToReference(String reference)
将视图滚动到给定的参考位置(即,显示的URL由
UL.getRef方法返回的值)。
|
void |
setContentType(String type)
设置此编辑器处理的内容类型。
|
void |
setEditorKit(EditorKit kit)
设置当前安装的工具包来处理内容。
|
void |
setEditorKitForContentType(String type, EditorKit k)
直接设置用于给定类型的编辑器工具包。
|
void |
setPage(String url)
设置显示的当前URL。
|
void |
setPage(URL page)
设置显示的当前URL。
|
void |
setText(String t)
将此
TextComponent的文本设置为指定的内容,预期其格式为此编辑器的内容类型。
|
addCaretListener, 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, setDocument, 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 static final String W3C_LENGTH_UNITS
默认情况下未启用; 使其能够将客户端property设置为Boolean.TRUE 。
public static final String HONOR_DISPLAY_PROPERTIES
默认值根据外观而异; 使其能够将客户端property设置为Boolean.TRUE 。
public JEditorPane()
JEditorPane 。
文档模型设置为null 。
public JEditorPane(URL initialPage) throws IOException
JEditorPane输入。
initialPage - 网址
IOException - 如果网址是
null或无法访问
public JEditorPane(String url) throws IOException
JEditorPane根据包含URL规范的字符串。
url - 网址
IOException - 如果网址是
null或无法访问
public JEditorPane(String type, String text)
JEditorPane已初始化为给定的文本。
这是一个方便的构造函数,它调用setContentType和setText方法。
type - 给定文本的MIME类型
text - 要初始化的文本;
可能是null
NullPointerException - 如果
type参数是
null
public void addHyperlinkListener(HyperlinkListener listener)
listener - 听众
public void removeHyperlinkListener(HyperlinkListener listener)
listener - 听众
public HyperlinkListener[] getHyperlinkListeners()
HyperLinkListener的数组。
HyperLinkListener添加或一个空数组,如果没有添加听众
public void fireHyperlinkUpdate(HyperlinkEvent e)
EditorKit 。
侦听器列表被最后处理。
e - 事件
EventListenerList
public void setPage(URL page) throws IOException
null ,则会创建一个新的默认文档,并将URL读入。
如果URL包含和参考位置,则将通过调用scrollToReference方法将位置滚动到。
如果所需的URL是当前显示的URL,则不会重新加载该文档。
要强制文档重新加载,有必要清除文档的流描述属性。
以下代码显示了如何做到这一点:
Document doc = jEditorPane.getDocument();
doc.putProperty(Document.StreamDescriptionProperty, null);
如果所需的URL不是当前正在显示的URL,那么getStream方法来对所提供的流进行子类控制。
此可以根据由所述返回的文档载入同步或异步EditorKit 。 如果Document类型为AbstractDocument ,并且具有大于或等于零的AbstractDocument.getAsynchronousLoadPriority返回的值,则该页面将使用该优先级加载到单独的线程上。
如果文档是同步加载的,则在将其安装到编辑器之前,它将被填入流中,并调用setDocument ,该setDocument被绑定并将触发属性更改事件。 如果IOException抛出部分加载文件将被丢弃,无论是文档或页面属性更改事件将被解雇。 如果文档已成功加载并安装,UI将会为其构建一个视图,然后在必要时将其滚动,然后页面属性更改事件将被触发。
如果文档异步加载,文档将立即安装到编辑器中,调用setDocument将触发文档属性更改事件,然后将创建一个将开始进行实际加载的线程。 在这种情况下,页面属性更改事件不会直接调用此方法触发,而是在执行加载的线程完成时触发。 它也将在事件发送线程上触发。 由于调用线程在另一个线程发生故障时不能抛出IOException ,所以当另一个线程完成时,页面属性更改事件将被触发,无论加载是否成功。
page - 网页的URL
IOException - 对于
null或无效页面规范,或正在读取的流中的异常
getPage()
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)
protected InputStream getStream(URL page) throws IOException
setPage方法加载的给定URL的流。
默认情况下,这只是打开URL并返回流。
这可以重新实现,以执行有用的事情,如从缓存获取流,监视流的进度等。
预计这种方法将具有建立内容类型的副作用,因此设置适当的EditorKit用于加载流。
如果这个流是http连接,则重定向将被跟随,并将生成的URL设置为Document.StreamDescriptionProperty ,以便可以正确解析相对URL。
page - 页面的URL
IOException
public void scrollToReference(String reference)
UL.getRef方法返回的值)。
默认情况下,此方法只知道如何在HTMLDocument中定位引用。
实现调用scrollRectToVisible方法来完成实际的滚动。
如果HTML之外的文档类型需要滚动到参考位置,则该方法应该被重新实现。
如果组件不可见,此方法将不起作用。
reference - 要滚动的命名位置
public URL getPage()
null ,并且相对URL将无法解析。
null如果没有
public void setPage(String url) throws IOException
url - 显示的网址
IOException - 对于
null或无效的URL规范
public String getUIClassID()
getUIClassID在
JComponent
JComponent.getUIClassID() ,
UIDefaults.getUI(javax.swing.JComponent)
protected EditorKit createDefaultEditorKit()
PlainEditorKit )。
public EditorKit getEditorKit()
createDefaultEditorKit ,调用createDefaultEditorKit设置默认值。
public final String getContentType()
EditorKit的类型。
null如果没有编辑器套件设置
public final void setContentType(String type)
getEditorKitForContentType ,然后setEditorKit如果一个编辑器工具包可以被成功定位。
这主要是方便的方法,可以直接用来调用setEditorKit 。
如果存在指定为内容类型规范参数的字符集定义,则在使用关联的EditorKit加载输入流时将使用该EditorKit 。 例如,如果类型被指定为text/html; charset=EUC-JP内容将使用加载EditorKit注册为text/html与读者提供给EditorKit为Unicode装入文件将使用EUC-JP字符集用于翻译为Unicode。 如果类型无法识别,内容将采用加载EditorKit纯文本注册, text/plain 。
type - 非
null mime类型的内容编辑支持
NullPointerException - 如果
type参数是
null
getContentType()
public void setEditorKit(EditorKit kit)
null ,则安装新套件,并为其创建一个默认文档。
当setEditorKit时,总是触发PropertyChange事件(“editorKit”)。
注意:这具有改变模型的副作用,因为EditorKit是特定类型的内容被建模的根源。 这种方法将导致setDocument被调用来代表调用者,以确保内部状态的完整性。
kit - 所需的编辑器行为
getEditorKit()
public EditorKit getEditorKitForContentType(String type)
EditorKit EditorKit,则会尝试从默认的EditorKit注册表创建一个EditorKit 。
如果失败,一个PlainEditorKit被用在所有的文本文档可以表示为纯文本的假设。
该方法可以重新实现,以使用其他类型的注册表。 例如,这可以重新实现为使用Java激活框架。
type - 非
null内容类型
public void setEditorKitForContentType(String type, EditorKit k)
createEditorKitForContentType为具有外观和感觉偏见的内容类型安装处理程序。
type - 非
null内容类型
k - 要设置的编辑工具包
public void replaceSelection(String content)
null ),则相当于删除当前选择。
替换文本将具有当前为输入定义的属性。
如果组件不可编辑,则发出哔声并返回。
replaceSelection在
JTextComponent
content - 用于替换选择的内容。
该值可以是null
public static EditorKit createEditorKitForContentType(String type)
ClassLoader ,那ClassLoader将用于加载原型。
如果没有注册ClassLoader , Class.forName将被用于加载该原型。
一旦原型EditorKit实例成功找到,它被克隆并且返回克隆。
type - 内容类型
null如果没有注册给定的类型
public static void registerEditorKitForContentType(String type, String classname)
type到classname 。
该类将在实际需要时稍后动态加载,并且可以在尝试使用之前安全地更改,以避免加载不需要的类。
当使用此方法Class.forName时,原型EditorKit将加载Class.forName 。
type - 非
null内容类型
classname - 稍后加载的类
public static void registerEditorKitForContentType(String type, String classname, ClassLoader loader)
type到classname 。
该类将在实际需要时使用给定的ClassLoader进行动态加载,并且可以在尝试使用之前安全地更改,以避免加载不需要的类。
type - 非
null内容类型
classname - 稍后加载的类
loader - 用于加载名称的
ClassLoader
public static String getEditorKitClassNameForContentType(String type)
EditorKit类名称,类型为
type 。
type - 非
null内容类型
public Dimension getPreferredSize()
JEditorPane 。
JEditorPane的首选大小与JEditorPane的首选大小略有变化。
如果视口的大小已经变得小于组件的最小尺寸,则跟踪宽度或高度的可滚动定义将变为false。
默认的视口布局将给出首选的大小,而在可滚动跟踪的情况下不需要。
在这种情况下, 正常的优选尺寸被调整到最小尺寸。
这样可以让HTML表格缩小到最小尺寸,然后将其放在最小尺寸上,拒绝进一步缩小。
getPreferredSize在
JComponent
Dimension包含首选大小
JComponent.setPreferredSize(java.awt.Dimension) , ComponentUI
public void setText(String t)
TextComponent的文本设置为指定的内容,预期其格式为此编辑器的内容类型。
例如,如果类型设置为text/html ,则应以HTML格式指定字符串。
这是为了删除当前文档的内容,并通过使用当前的EditorKit解析给定的字符串来替换它们。 这通过不改变模型来提供超类的语义,同时支持当前在此组件上设置的内容类型。 假设以前的内容相对较小,并且以前的内容没有副作用。 这两个假设都可能被违反并导致不合需要的结果。 为了避免这种情况,创建一个新的文档, getEditorKit().createDefaultDocument() ,并用现有的Document替换新的。 然后你们放心,以前的Document将不会有任何滞留状态。
使用字符串加载该组件的另一种方法是创建一个StringReader并调用read方法。 在这种情况下,在使用字符串的内容初始化之后,模型将被替换。
setText在
JTextComponent
t - 要设置的新文本;
如果null的旧文本将被删除
getText()
public String getText()
TextComponent中包含的文本。
如果在尝试检索文本时抛出异常,将返回null 。
这是实现调用JTextComponent.write与一个StringWriter 。
getText在
JTextComponent
setText(java.lang.String)
public boolean getScrollableTracksViewportWidth()
Scrollable的宽度与视口的宽度相匹配,则返回true。
getScrollableTracksViewportWidth在界面
Scrollable
getScrollableTracksViewportWidth在
JTextComponent
public boolean getScrollableTracksViewportHeight()
Scrollable的高度与视口的高度相匹配,则返回true。
getScrollableTracksViewportHeight在界面
Scrollable
getScrollableTracksViewportHeight在
JTextComponent
Scrollable的高度匹配自己,否则为true
protected String paramString()
JEditorPane的字符串表示JEditorPane 。
该方法仅用于调试目的,并且返回的字符串的内容和格式可能因实现而异。
返回的字符串可能为空,但可能不是null 。
paramString在
JTextComponent
JEditorPane的字符串表示
JEditorPane
public AccessibleContext getAccessibleContext()
getAccessibleContext在接口
Accessible
getAccessibleContext在
JTextComponent
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.