Java JEditorPane2025年3月17日 | 阅读 3 分钟 JEditorPane 类用于创建一个简单的文本编辑器窗口。这个类有 setContentType() 和 setText() 方法。 setContentType("text/plain"): 此方法用于将内容类型设置为纯文本。 setText(text): 此方法用于设置初始文本内容。 嵌套类修饰符和类型 | Class | 描述 |
---|
受保护的类 | JEditorPane.AccessibleJEditorPane | 此类实现了对 JEditorPane 类的辅助功能支持。 | 受保护的类 | JEditorPane.AccessibleJEditorPaneHTML | 此类提供对 AccessibleHypertext 的支持,并在 JEditorPane 中安装的 EditorKit 是 HTMLEditorKit 的实例时使用。 | 受保护的类 | JEditorPane.JEditorPaneAccessibleHypertextSupport | AccessibleJEditorPaneHTML.getAccessibleText 返回什么 |
字段修饰符和类型 | 字段 | 描述 |
---|
static String | HONOR_DISPLAY_PROPERTIES | 一个客户端属性的键,用于指示如果未在样式文本中指定字体或前景色,是否使用组件的默认字体和前景色。 | static String | W3C_LENGTH_UNITS | 一个客户端属性的键,用于指示是否对 HTML 渲染使用符合 W3C 标准的长度单位。 |
构造函数构造函数 | 描述 |
---|
JEditorPane() | 它创建一个新的 JEditorPane。 | JEditorPane(String url) | 它基于一个包含 URL 规范的字符串创建一个 JEditorPane。 | JEditorPane(String type, String text) | 它创建一个已初始化为给定文本的 JEditorPane。 | JEditorPane(URL initialPage) | 它基于指定的 URL 用于输入创建一个 JEditorPane。 |
有用的方法修饰符和类型 | 方法 | 描述 |
---|
void | addHyperlinkListener(HyperlinkListener listener) | 添加一个超链接监听器,用于通知任何更改,例如选择和输入链接时。 | protected EditorKit | createDefaultEditorKit() | 它在首次创建组件时创建默认的编辑器套件 (PlainEditorKit)。 | void | setText(String t) | 它将此 TextComponent 的文本设置为指定的内容,该内容应与此编辑器的内容类型格式一致。 | void | setContentType(String type) | 它设置此编辑器处理的内容类型。 | void | setPage(URL page) | 它设置当前正在显示的 URL。 | void | read(InputStream in, Object desc) | 此方法从流进行初始化。 | void | scrollToReference(String reference) | 它将视图滚动到给定的参考位置(即,UL.getRef 方法为正在显示的 URL 返回的值)。 | void | setText(String t) | 它将此 TextComponent 的文本设置为指定的内容,该内容应与此编辑器的内容类型格式一致。 | String | getText() | 它根据此编辑器的内容类型返回此 TextComponent 中包含的文本。 | void | read(InputStream in, Object desc) | 此方法从流进行初始化。 |
JEditorPane 示例输出  JEditorPane 示例:使用 HTML输出 
|