An RTF document contains a set of code when you view it in a text editor, codes that only RTF readers and clients can understand. Replacing contents in an RTF document can be tricky. The source code in this post converts new line characters into pilcrow symbols and space characters as dot symbols (see image).

The source code was made by my friend sumpix. To correctly make use of this class, make sure that the RTFEditorKit uses a DefaultStyledDocument as its document. The JTextPane object passed to the RTFEditorKit class will have a KeyListener that when ALT-P is pressed, conversion of new lines and space characters to their intended symbols will occur. Any key pressed after that will convert it back to its original.

To use the class, do this:

Get the customized RTFEditorKit class here.

Related Posts Plugin for WordPress, Blogger...