Java JEditorPane

2025年3月17日 | 阅读 3 分钟

JEditorPane 类用于创建一个简单的文本编辑器窗口。这个类有 setContentType() 和 setText() 方法。

setContentType("text/plain"): 此方法用于将内容类型设置为纯文本。

setText(text): 此方法用于设置初始文本内容。

嵌套类

修饰符和类型Class描述
受保护的类JEditorPane.AccessibleJEditorPane此类实现了对 JEditorPane 类的辅助功能支持。
受保护的类JEditorPane.AccessibleJEditorPaneHTML此类提供对 AccessibleHypertext 的支持,并在 JEditorPane 中安装的 EditorKit 是 HTMLEditorKit 的实例时使用。
受保护的类JEditorPane.JEditorPaneAccessibleHypertextSupportAccessibleJEditorPaneHTML.getAccessibleText 返回什么

字段

修饰符和类型字段描述
static StringHONOR_DISPLAY_PROPERTIES一个客户端属性的键,用于指示如果未在样式文本中指定字体或前景色,是否使用组件的默认字体和前景色。
static StringW3C_LENGTH_UNITS一个客户端属性的键,用于指示是否对 HTML 渲染使用符合 W3C 标准的长度单位。

构造函数

构造函数描述
JEditorPane()它创建一个新的 JEditorPane。
JEditorPane(String url)它基于一个包含 URL 规范的字符串创建一个 JEditorPane。
JEditorPane(String type, String text)它创建一个已初始化为给定文本的 JEditorPane。
JEditorPane(URL initialPage)它基于指定的 URL 用于输入创建一个 JEditorPane。

有用的方法

修饰符和类型方法描述
voidaddHyperlinkListener(HyperlinkListener listener)添加一个超链接监听器,用于通知任何更改,例如选择和输入链接时。
protected EditorKitcreateDefaultEditorKit()它在首次创建组件时创建默认的编辑器套件 (PlainEditorKit)。
voidsetText(String t)它将此 TextComponent 的文本设置为指定的内容,该内容应与此编辑器的内容类型格式一致。
voidsetContentType(String type)它设置此编辑器处理的内容类型。
voidsetPage(URL page)它设置当前正在显示的 URL。
voidread(InputStream in, Object desc)此方法从流进行初始化。
voidscrollToReference(String reference)它将视图滚动到给定的参考位置(即,UL.getRef 方法为正在显示的 URL 返回的值)。
voidsetText(String t)它将此 TextComponent 的文本设置为指定的内容,该内容应与此编辑器的内容类型格式一致。
StringgetText()它根据此编辑器的内容类型返回此 TextComponent 中包含的文本。
voidread(InputStream in, Object desc)此方法从流进行初始化。

JEditorPane 示例

输出

Java JEditorpane

JEditorPane 示例:使用 HTML

输出

Java JEditorpane 2
下一主题Java JScrollPane