Solved

Changing fonts using RTFEditorKit

Posted on 2004-08-17
3
1,046 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
  • 2
3 Comments
 
LVL 35

Accepted Solution

by:
girionis earned 250 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

705 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now