java.lang.Object
javax.swing.AbstractAction
javax.swing.text.TextAction
javax.swing.text.StyledEditorKit.StyledTextAction
javax.swing.text.html.HTMLEditorKit.HTMLTextAction
javax.swing.text.html.HTMLEditorKit.InsertHTMLTextAction
- 所有已实现的接口:
ActionListener,Serializable,Cloneable,EventListener,Action
- 封闭类:
HTMLEditorKit
InsertHTMLTextAction 可用于将任意 HTML 字符串插入现有的 HTML 文档中。至少需要提供两个 HTML.Tags。第一个标签 parentTag 标识要向其添加元素的文档中的父级。第二个标记 addTag 标识应添加到文档中的第一个标记,如 HTML 字符串中所示。要记住的一件重要事情是,解析器将生成所有适当的标记,即使它们不在传入的 HTML 字符串中。
例如,假设您想要创建一个将表格插入正文的操作。 parentTag 将是 HTML.Tag.BODY,addTag 将是 HTML.Tag.TABLE,字符串可能类似于 <table><tr><td></td></tr></table>。
还有一个选项可以提供备用 parentTag 和 addTag。如果偏移处没有 parentTag,将检查这些。
-
字段摘要
字段修饰符和类型Field描述protected HTML.TagHTML 中的标记以开始添加标记。protected HTML.Tag如果未找到 parentTag 且找到 alternateParentTag,HTML 中的备用标记将开始添加标记。protected HTML.Tag如果未找到 parentTag,则要在文档中检查的备用标记。protected String要插入的 HTML。protected HTML.Tag要在文档中检查的标记。在类 javax.swing.AbstractAction 中声明的字段
changeSupport, enabled在接口 javax.swing.Action 中声明的字段
ACCELERATOR_KEY, ACTION_COMMAND_KEY, DEFAULT, DISPLAYED_MNEMONIC_INDEX_KEY, LARGE_ICON_KEY, LONG_DESCRIPTION, MNEMONIC_KEY, NAME, SELECTED_KEY, SHORT_DESCRIPTION, SMALL_ICON -
构造方法总结
构造方法 -
方法总结
修饰符和类型方法描述void将 HTML 插入到文档中。protected voidinsertAtBoundary(JEditorPane editor, HTMLDocument doc, int offset, Element insertElement, String html, HTML.Tag parentTag, HTML.Tag addTag) 在边界插入时调用此方法。protected voidinsertAtBoundry(JEditorPane editor, HTMLDocument doc, int offset, Element insertElement, String html, HTML.Tag parentTag, HTML.Tag addTag) 已弃用。从 Java 2 平台 v1.3 开始,使用 insertAtBoundaryprotected voidinsertHTML(JEditorPane editor, HTMLDocument doc, int offset, String html, int popDepth, int pushDepth, HTML.Tag addTag) HTMLEditorKit.insertHTML 的封面。在类 javax.swing.text.html.HTMLEditorKit.HTMLTextAction 中声明的方法
elementCountToTag, findElementMatchingTag, getElementsAt, getHTMLDocument, getHTMLEditorKit在类 javax.swing.text.StyledEditorKit.StyledTextAction 中声明的方法
getEditor, getStyledDocument, getStyledEditorKit, setCharacterAttributes, setParagraphAttributes在类 javax.swing.text.TextAction 中声明的方法
augmentList, getFocusedComponent, getTextComponent在类 javax.swing.AbstractAction 中声明的方法
addPropertyChangeListener, clone, firePropertyChange, getKeys, getPropertyChangeListeners, getValue, isEnabled, putValue, removePropertyChangeListener, setEnabled
-
字段详细信息
-
html
要插入的 HTML。 -
parentTag
要在文档中检查的标记。 -
addTag
HTML 中的标记以开始添加标记。 -
alternateParentTag
如果未找到 parentTag,则要在文档中检查的备用标记。 -
alternateAddTag
如果未找到 parentTag 且找到 alternateParentTag,HTML 中的备用标记将开始添加标记。
-
-
构造方法详细信息
-
插入 HTMLTextAction
创建一个新的 InsertHTMLTextAction。- 参数:
name- 动作名称html- 一个 HTML 字符串parentTag- 父标签addTag- 开始插入文档的第一个标签
-
插入 HTMLTextAction
public InsertHTMLTextAction(String name, String html, HTML.Tag parentTag, HTML.Tag addTag, HTML.Tag alternateParentTag, HTML.Tag alternateAddTag) 创建一个新的 InsertHTMLTextAction。- 参数:
name- 动作名称html- 一个 HTML 字符串parentTag- 父标签addTag- 开始插入文档的第一个标签alternateParentTag- 替代父标签alternateAddTag- 替代标签
-
-
方法详情
-
insertHTML
protected void insertHTML(JEditorPane editor, HTMLDocument doc, int offset, String html, int popDepth, int pushDepth, HTML.Tag addTag) HTMLEditorKit.insertHTML 的封面。如果抛出异常,则将其包装在 RuntimeException 中并抛出。- 参数:
editor- JEditorPane 的一个实例doc- 要插入的文档offset- 插入 HTML 的偏移量html- 一个 HTML 字符串popDepth- 插入前要生成的 ElementSpec.EndTagType 的数量pushDepth- 方向为 ElementSpec.JoinNextDirection 的 ElementSpec.StartTagType 的数量,应该在插入之前生成,但在生成结束标记之后addTag- 开始插入文档的第一个标签
-
insertAtBoundary
protected void insertAtBoundary(JEditorPane editor, HTMLDocument doc, int offset, Element insertElement, String html, HTML.Tag parentTag, HTML.Tag addTag) 在边界插入时调用此方法。它确定弹出次数,然后确定需要执行的推送次数,然后调用 insertHTML。- 参数:
editor- JEditorPane 的一个实例doc- HTMLDocument 的实例offset- 开始的偏移量insertElement- 元素的实例html- 一个 HTML 字符串parentTag- 父标签addTag- 开始插入文档的第一个标签- 自从:
- 1.3
-
insertAtBoundry
@Deprecated protected void insertAtBoundry(JEditorPane editor, HTMLDocument doc, int offset, Element insertElement, String html, HTML.Tag parentTag, HTML.Tag addTag) 已弃用。从 Java 2 平台 v1.3 开始,使用 insertAtBoundary在边界插入时调用此方法。它确定弹出次数,然后确定需要执行的推送次数,然后调用 insertHTML。- 参数:
editor- JEditorPane 的一个实例doc- HTMLDocument 的实例offset- 开始的偏移量insertElement- 元素的实例html- 一个 HTML 字符串parentTag- 父标签addTag- 开始插入文档的第一个标签
-
actionPerformed
将 HTML 插入到文档中。- 参数:
ae- 事件
-