I have the same problem when i put two instances of HTMLEditor in the same panel with a cardlayout.
To fix it, replace the inner class ParaBreakAction of HTMLEditor by :
class ParaBreakAction extends AbstractAction {
ParaBreakAction() {
super("ParaBreakAction");
}
I have the same problem when i put two instances of HTMLEditor in the same panel with a cardlayout.
To fix it, replace the inner class ParaBreakAction of HTMLEditor by :
class ParaBreakAction extends AbstractAction {
ParaBreakAction() {
super("ParaBreakAction");
}
public void actionPerformed(ActionEvent e) {
HTMLEditorPane hep = (HTMLEditorPane) e.getSource();
HTMLEditorKit kit = (HTMLEditorKit)hep.getEditorKit();
HTMLDocument document = (HTMLDocument)hep.getDocument();
Element elem = document.getParagraphElement(hep.getCaretPosition());
String elName = elem.getName().toUpperCase();
String parentname = elem.getParentElement().getName();
HTML.Tag parentTag = HTML.getTag(parentname);
if (parentname.toUpperCase().equals("P-IMPLIED"))
parentTag = HTML.Tag.IMPLIED;
if (parentname.toLowerCase().equals("li")) {
if (elem.getEndOffset() - elem.getStartOffset() > 1) {
try {
document.insertAfterEnd(elem.getParentElement(), "<li></li>");
hep.setCaretPosition(elem.getParentElement().getEndOffset());
} catch (Exception ex) {
ex.printStackTrace();
}
} else {
try {
document.remove(hep.getCaretPosition(), 1);
} catch (Exception ex) {
ex.printStackTrace();
}
Element listParentElement = elem.getParentElement().getParentElement()
.getParentElement();
HTML.Tag listParentTag = HTML.getTag(listParentElement.getName());
String listParentTagName = listParentTag.toString();
if (listParentTagName.toLowerCase().equals("li")) {
Element listAncEl = listParentElement.getParentElement();
try {
kit.insertHTML(document, listAncEl.getEndOffset(),
"<li><p></p></li>", 3, 0, HTML.Tag.LI);
} catch (Exception ex) {
ex.printStackTrace();
}
} else {
HTMLEditorKit.InsertHTMLTextAction pAction = new HTMLEditorKit.InsertHTMLTextAction(
"insertP", "<p></p>", listParentTag, HTML.Tag.P);
pAction.actionPerformed(e);
}
}
} else if ((elName.equals("PRE")) || (elName.equals("ADDRESS"))
|| (elName.equals("BLOCKQUOTE"))) {
if (hep.getCaretPosition() > 0)
removeIfEmpty(document.getParagraphElement(hep.getCaretPosition() - 1));
HTMLEditorKit.InsertHTMLTextAction pAction = new HTMLEditorKit.InsertHTMLTextAction(
"insertP", "<p></p>", parentTag, HTML.Tag.P);
System.out.println("PRE");
pAction.actionPerformed(e);
} else if (elName.equals("P-IMPLIED")) {
try {
System.out.println("IMPLIED");
document.insertAfterEnd(elem.getParentElement(), "<p></p>");
hep.setCaretPosition(elem.getParentElement().getEndOffset());
} catch (Exception ex) {
ex.printStackTrace();
}
} else {
hep.replaceSelection("\n");
kit.getInputAttributes().removeAttribute(HTML.Attribute.ID);
kit.getInputAttributes().removeAttribute(HTML.Attribute.CLASS);
}
}
}