Solved

Changing fonts using RTFEditorKit

Posted on 2004-08-17
3
1,086 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

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

Suggested Solutions

Title # Comments Views Activity
how to see all occupied ports on windows 10 laptop 15 82
maven module vs maven project 3 72
How to install a font on WIN2003SBS/IIS 6 & test 17 48
jmeter usage 4 33
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

740 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