?
Solved

Changing fonts using RTFEditorKit

Posted on 2004-08-17
3
Medium Priority
?
1,111 Views
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();
rtfEditorKit.read(_in,document,0);
_in.close();

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

// Write output
resp.setContentType("text/rtf");
OutputStream _out = resp.getOutputStream();
rtfEditorKit.write(_out, document,0,document.getLength());
_out.close();
0
Comment
Question by:matthew_york
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 35

Accepted Solution

by:
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:

http://javafaq.nu/java/free-swing-book/free-swing-book-chapter20.shtml
0
 
LVL 1

Author Comment

by:matthew_york
ID: 11818977
Excellent, thanks for your help
0
 
LVL 35

Expert Comment

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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month9 days, 7 hours left to enroll

762 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