gpt4 book ai didi

java - JEdi​​torPane 中的 HTMLEditorKit 和自定义标签

转载 作者:行者123 更新时间:2023-12-01 15:32:46 25 4
gpt4 key购买 nike

我使用说明添加我自己的标签 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) {
}
}

}

不幸的是它无法正常工作:
image
谁能帮我吗?

最佳答案

它适用于我使用以下(jdk 1.7):

Field f = javax.swing.text.html.parser.ParserDelegator.class.getDeclaredField("DTD_KEY");

唯一的变化是键:“DTD_KEY”大写!!

我使用

找到了 key “DTD_KEY”
Field[] flds = javax.swing.text.html.parser.ParserDelegator.class.getDeclaredFields();
for (Field f: flds)
{
System.err.println(f.getName());
}

关于java - JEdi​​torPane 中的 HTMLEditorKit 和自定义标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9379030/

25 4 0