How to implement bullet points in a JTextPane?

流过昼夜 提交于 2019-11-29 15:10:50

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:

Figured it out doing this:

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

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.

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