JEditorPane中的HTMLEditorKit和Custom标签 [英] HTMLEditorKit and Custom tags in the JEditorPane
本文介绍了JEditorPane中的HTMLEditorKit和Custom标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我按照说明添加了自己的标签 http://java-sl.com/custom_tag_html_kit. html
I use the instructions to add my own tag http://java-sl.com/custom_tag_html_kit.html
class MyParserDelegator extends ParserDelegator {
public MyParserDelegator() {
try {
Field f=javax.swing.text.html.parser.ParserDelegator.class.getDeclaredField("dtd");
f.setAccessible(true);
DTD dtd=(DTD)f.get(null);
javax.swing.text.html.parser.Element div=dtd.getElement("div");
dtd.defineElement("button", div.getType(), true, true,div.getContent(),null, null,div.getAttributes());
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
}
}
}
很遗憾,它无法正常工作:
谁能帮我吗?
Unfortunately it is not working properly:
Can anyone help me?
推荐答案
使用以下(jdk 1.7)可以为我工作:
It works for me using the following (jdk 1.7):
Field f = javax.swing.text.html.parser.ParserDelegator.class.getDeclaredField("DTD_KEY");
唯一的更改是键:"DTD_KEY"
大写!
The only change is the key: "DTD_KEY"
upper case!!
我使用
Field[] flds = javax.swing.text.html.parser.ParserDelegator.class.getDeclaredFields();
for (Field f: flds)
{
System.err.println(f.getName());
}
这篇关于JEditorPane中的HTMLEditorKit和Custom标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文