Java RTFEditor
I made the Java RTFEditor sources available to whoever interested.
RTFEditor is a tabbed, Swing based implementation of RTFEditorKit. It is just a demo application, you should not use it for anything else but testing. As RTFEditorKit does not support bulleted lists, neither does this implementation.
Java 6 is required to run RTFEditor (it won’t work on anything older because it makes use of JtabbedPane.setTabComponentAt).
Enjoy









Hi Claud, you’ve done a great job with this RTFEditor. Do you think it would be hard to modifty it so that it uses the HTMLEditorKit and can still save in an RTF Format?
I am working on this now but I’m still new to Java. Im trying to get to grips with the styling.
Well, thanks and keep up the great blog, I love the random and weird topics you discuss
Hi Vish, sorry for the huge delay but your comment got caught in the spam greylist and that concocted with a misfortunate PHP configuration resulted in me not getting any notification emails regarding this
I’m quite a beginner myself in Java, and I know how it feels when trying to understand the works of styled documents and such.
Anyway, there is a solution to your problem. I’ll take the case when you use the RTFEditorkit and save to HTML format. It should be the same for the other way around. In this little test I just did I noticed that JEditorPane does not really care of your editor kit (to a certain extent) as long as it implements a set of methods it lives on - write, read, etc (yes, this means you could be writing your own editor kit!).
In this test, I wrote to a file in HTML format the contents of the editor pane.
I declared and instantiated an output stream to a file:
OutputStream out2 = new FileOutputStream(new File("c:\\test.html"));Then I declared and instantiated my HTMLEditorKit:
HTMLEditorKit htmlEditorKit= new HTMLEditorKit();And then I wrote to file using this editor kit:
htmlEditorKit.write(out2,getDocument(),0,getDocument().getLength());Finally, I closed the output stream:
out2.close();If you have the sources for RTFEditor you could see for yourself by adding these lines in RTFDocument::save() in the try{} block.
I believe this will work for your case as well, in the end, it’s just a reversal of this one.
Hope this helps
Clau
Hi Clau..
Thanks for your reply, dont worry about the delay, those spam detectors are always failing us… I havent tried the HTML Save just yet because im working a way to inset and more importantly, save/load images. I will let you know how this goes.
You dont seem like a Java novice, how did you learn Java?
Hi Vish! I consider myself more of a medium level novice
I developed most of my Java skills last semester in school when I worked on this editor (which is quite obvious, because there are several design flaws in it
).
I’ll provide you with the following links which were a godsend for me:
Trail: Creating a GUI with JFC/Swing
http://java.sun.com/docs/books/tutorial/uiswing/TOC.html
Java Technology Forums (I’m pretty sure that the issue of inserting images in the document has already been discussed, better use the search to look for it)
http://forum.java.sun.com/index.jspa
And the following Swing book (totally free):
http://www.javafaq.nu/java-allbooks-8.html
The Swing book contains a similar RTFEditor as an example, it proved very useful.
And, the last one, Java Tips (a collection of examples):
http://www.java-tips.org/java-se-tips/
Hope this helps you. Good luck
Thanks Clau.. I will have a look. I have read of a possible work around for inseting. saving/loading images in rtf which I am currently working on as no one has provided any code for it.
I learn all of my Java Skills by seeing examples but to be honest with you, I havent had a very good experience with it so far. Just look at the RTFEditorKit, it cant save alignment values so everything is always left aligned, and it cant handle images or bullets etc. It would be much better just to make a HTML editor wouldnt it.
I have a simple challenge for u… I have an example of a HTML editor which currently saves in HTML format. Do you think you could convert the contents of the JTextPane used by the HTML editor and save them as RTF?
Vish
Hi! I can’t promise you anything, but I will take a look over your code and hopefully give you a few ideas after I make some tests