Solved

Changing fonts using RTFEditorKit

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Convert from a json string array to a Java object 3 80
how to debug htl and js pages 8 78
hashmap order 17 62
passing enum to a method 4 50
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This video teaches viewers about errors in exception handling.
Suggested Courses

734 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