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