javax.swing.text.rtf


1. Basic RTF Document Creation

import javax.swing.text.rtf.RTFEditorKit;

RTFEditorKit rtfKit = new RTFEditorKit();
Document doc = rtfKit.createDefaultDocument();

2. Loading an RTF Document from a File

import javax.swing.JEditorPane;
import javax.swing.text.Document;
import javax.swing.text.rtf.RTFEditorKit;

JEditorPane editorPane = new JEditorPane();
RTFEditorKit rtfKit = new RTFEditorKit();
editorPane.setEditorKit(rtfKit);
editorPane.getDocument().putProperty(Document.StreamDescriptionProperty, new File("sample.rtf"));

3. Saving an RTF Document to a File

import javax.swing.JEditorPane;
import javax.swing.text.Document;
import javax.swing.text.rtf.RTFEditorKit;

JEditorPane editorPane = new JEditorPane();
RTFEditorKit rtfKit = new RTFEditorKit();
editorPane.setEditorKit(rtfKit);
rtfKit.write(editorPane.getDocument(), new FileOutputStream("saved.rtf"));

4. Formatting Text

5. Inserting Images

6. Creating Nested Lists

7. Adding Hyperlinks

8. Using Tables

9. Controlling Paragraph Properties

10. Using Annotations

11. Listening for Document Changes

12. Customizing the Editor Bar

13. Extending RTFEditorKit

14. Converting HTML to RTF

15. Converting RTF to HTML

16. Highlighting Keywords

17. Managing Headers and Footers