How to implement bullet points in a JTextPane?

妖精的绣舞 提交于 2019-12-18 09:01:03

问题


I have a JTextPane with a StyledDocument and RTFEditorKit implemented.

How can I add bullet points (preferrably multi-level ones) onto the JTextPane?


回答1:


Well it does not have built in support for this, however here is a great link with tutorial on creating bulleted and numbered lists in JTextPane and JEditorPanes:

  • Bullets and Numberings in the JEditorPane/JTextPane.



回答2:


Figured it out doing this:

HTMLEditorKit.InsertHTMLTextAction bulletAction = new HTMLEditorKit.InsertHTMLTextAction("Bullet", "<li> </li>", HTML.Tag.BODY, HTML.Tag.UL);  



回答3:


I know this is an old question, but what I have done is:

private final Action ORDERED_LIST_ACTION = new HTMLEditorKit.InsertHTMLTextAction("ORDERED-LIST", "<ol> </ol>", HTML.Tag.BODY, HTML.Tag.OL);
private final Action UNORDERED_LIST_ACTION = new HTMLEditorKit.InsertHTMLTextAction("UNORDERED-LIST", "<ul> </ul>", HTML.Tag.BODY, HTML.Tag.UL);
private final Action LIST_ITEM_ACTION = new HTMLEditorKit.InsertHTMLTextAction("BULLET", "<li> </li>", HTML.Tag.UL, HTML.Tag.LI, HTML.Tag.OL, HTML.Tag.LI);

When I have list creation and bullet creation as separate actions the interaction seems to work much better.



来源:https://stackoverflow.com/questions/11526992/how-to-implement-bullet-points-in-a-jtextpane

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!