Articles Projects Tips Downloads Contacts About

Advanced RTFEditorKit library in JEditorPane/JTextPane.


Default RTFEditorKit from JDK provided by SUN has restricted functionality. Features like paragraph attributes, images and tables just aren't supported. The library is an attempt to provide missing functionality.

The Advanced RTFEditorKit supports MS Word 2000 compatible rtf format. Following features:
- Tables (and nested tables as well). Inner cell margins and cell's content vertical alignment aren't supported.
- Images. PNG format is used because it's default MS Word's format. It can process JPG, GIF (all formats which are supported by java) too.
- Headers/Footers. Common header/footer, First, Even, Odd page's headers/footers. When document is read new documents for header/footer is  created and stored in the properties of main document. So header/footer's  documents support the same functionality.
- Paragraph attributes (alignment, indents, spacing).
- Text attributes (colors, fonts, effects).

The AdvancedRTFEditorKit screenshot shows how it looks:

To show RTF file in JEditorPane use following code:

        JEditorPane editorPane=new JEditorPane();
        editorPane.setEditorKit(new AdvancedRTFEditorKit()); FileInputStream(pathToRTFFile));
        String rtfString=null;
        //some code to init the string

The kit is free to use as is but the source code isn't free. If you need the AdvancedRTFEditorKit source code to use or change please contact me.

Click here to get AdvancedRTFEditorKit library. The source code is not included. To work with images you need the jai_codec.jar library to be included in your classpath.