简体   繁体   中英

How to implement bullet points in a JTextPane?

I have a JTextPane with a StyledDocument and RTFEditorKit implemented.

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

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 JEditorPane s:

想通了,这样做:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM