JTextPane does not have bulleted list or numbered list support. While making it happen using either StyledEditorKit or RTFEditorKit is not possible unless you create your own, I figure the easiest way to implement this feature would be through the use of an HTMLEditorKit since HTML supports both unordered and ordered lists.

The code below inserts HTML code of an unordered list into the JTextPane. For ordered or numbered lists, you can change the variables of the code and replace the <UL> HTML tag to <OL>.

I was trying to make an editor component that included the same functionalities that you would see in editing softwares. Functions like bold, underline, italicize, left align and others. The component I used is a JTextPane and since the code deals with RTF, I used an RTFEditorKit as the EditorKit.

Common functions like bold, underline, italicize, left-right-center align, cut, copy and paste are very simple since Action classes are already part of DefaultEditorKit and RTFEditorKit respectively. However, I was stumped when I tried to incorporate bullet and numbered lists. It seems they are not supported in RTFEditorKit. If the JTextPane would have HTML formatting, it would have been possible but since the format is in RTF, the only possible way for this to happen is to create my own.

Well, I did not. It is not an easy task. I would have to familiarize myself with a bevy of other classes. I did manage to find a working sample of a bullet and numbered list but the code based itself on HTML content. Oh well … the last alternative would be to buy a commercial 3rd party library of an editor.

I also learned that it was not the Java Dev Team responsible for creating the RTF support. And unless they are going to add this feature in the next JDK version (7), I will consider the RTFEditorKit class as incomplete.

Related Posts Plugin for WordPress, Blogger...