I m Religioning with JEditorPane
. 我需要简单的编辑。 我先解决了这一问题,并修改了含有习惯(两)标签的超文本(见my Senior post )。 它恰当地展示了该文件,现在我甚至可以it。 我可以撰写案文,删除文字或习惯内容。 我赢得了一场战斗,但 t子赢得了战争。 下一个步骤令人遗憾地也非常成问题。 我无法插入我的习俗标签。
我有习惯行动:
import my.own.HTMLEditorKit; //extends standard HTMLEditorKit
import my.own.HTMLDocument; //extends standard HTMLDocument
class InsertElementAction extends StyledTextAction {
private static final long serialVersionUID = 1L;
public InsertElementAction(String actionName) {
super(actionName);
}
@Override
public void actionPerformed(ActionEvent e) {
JEditorPane editor = getEditor(e);
if (editor == null)
return;
HTMLDocument doc = (HTMLDocument) editor.getDocument();
HTMLEditorKit ekit = (HTMLEditorKit) editor.getEditorKit();
int offset = editor.getSelectionStart();
try {
ekit.insertHTML(doc, offset, "<span>ahoj</span>", 0, 0, HTML.Tag.SPAN);
Element ele = doc.getRootElements()[0];
ele = ele.getElement(1).getElement(0);
doc.setInnerHTML(ele, "<bar medium="#DEFAULT" type="packaged" source="identifier" />");
}
catch (BadLocationException ble) {
throw new Error(ble);
}
catch (IOException ioe) {
throw new Error(ioe);
}
}
}
它工作得当。 页: 1 但我不能以这种方式插入非标准标签。 我可以仅插入<条码><>代码/代码>,span
,等等,但不是我的标签。 我的帽子Im被迫使用:
ekit.insertHTML(doc, offset, "x<bar medium="#DEFAULT" type="packaged" source="identifier" />x", 0, 0, null);
有两个关键问题:
- The custom tag must be bounded with non-whispace characters (here x)
- The current element s body is split
在I插入span
元素后插入<p>/p>
<p>par<span>ahoj</span>agraph</p>。 Howerever known tag is allways included as child of one/code> elements and the result (e.g. for known tag
x
;p>par</p><x>ahoj</x><p>agraph</p>
。
The work is dead exhausting. I m faithing with this relatively simple task since weeks. I m already wasted. If the insertion won t to work, I can scrap it all...