JTextPane - Bullet with HTMLEditorKit list not rendering correctly unless I do setText(getText()) and repaint

后端 未结 2 2000
抹茶落季
抹茶落季 2021-01-17 03:37

I have:

JTextPane jtextPane = new JTextPane();
jtextPane.setEditorKit(new HTMLEditorKit());
...

Then later I try to add an unordered list b

2条回答
  •  执念已碎
    2021-01-17 04:39

    The answer is actually quite complex. Basically the InsertHtmlAction is just not good enough by itself. You need a lot of work and logic to get to a working list action. It requires a lot of logic! So you definitely have to override the Action class. Basically the parameters of the InsertHtmlAction will change depending on where in the html code you are.

    That being said, I studied several open source solutions to get a better understanding for what was all involved. Many long hours later (and many hours spent beforehand as well), and I was finally able to figure it out well enough for what I needed. But it is fairly complex. Too complex to write about here, it would take a chapter of a book just to explain the concepts. And even then I'm still fuzzy on some details (I'm still working through it).

    I can now understand why people sell components for this!

    I found that most open source solutions don't really deal nicely with lists. They generally somewhat work but most have glaring bugs. That or they just don't really handle anything but the most basic cases of lists.

    Here is a list of systems I looked at to understand how they work to get a better understanding of everything. I unfortunately found the documentation lacking or hard to understand, so looking at these projects helped me more than anything else.

    The most helpful

    • Shef - Most helpful of all.
    • ekit - Decent but many bugs and not the best code organization
    • MetaphaseEditor - Similar to ekit

    Moderately helpful (more complex, buggy, less relevant, etc.)

    • OOoBean - Tried but too much (and hence too much complexity) for what I needed. Looks really good though, you just need to invest time.
    • JXHTMLEdit - Seemed interest

    Additional links

    • JWebEngine - Mostly for rendering
    • Joeffice - Interesting but it's all videos and wasn't enough ready enough yet.
    • Richtext - No comments. I only briefly looked at it.
    • JRichTextEditor - No comments either, same thing.

    Paid

    • JWord - Look very interesting but it was beyond the budget for what I was doing.

提交回复
热议问题