Changing fonts using RTFEditorKit

Posted on 2004-08-17
Medium Priority
Last Modified: 2013-12-03
I have a rtf file that I am reading in from the file system adding some text and writing the rtf. How can I go about changing the font of the inserted text. This is my class so far:

// Read in
FileInputStream _in = new FileInputStream("c:\\temp\\in.rtf");
RTFEditorKit rtfEditorKit = new RTFEditorKit();
Document document = rtfEditorKit.createDefaultDocument();

// Insert text
Position pos = document.createPosition(10);
document.insertString(pos.getOffset(),"Inserted Text",rtfEditorKit.getInputAttributes());

// Write output
OutputStream _out = resp.getOutputStream();
rtfEditorKit.write(_out, document,0,document.getLength());
Question by:matthew_york
  • 2
LVL 36

Accepted Solution

girionis earned 1000 total points
ID: 11818674
Not sure if this will help but try to use the StyleConstants.setFontFamily(attr, <family name>); The "attr" parameter should be an object of type MutableAttributeSet. For more info:


Author Comment

ID: 11818977
Excellent, thanks for your help
LVL 36

Expert Comment

ID: 11818984
Thank you for accepting, glad I was of help :)

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

600 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question