File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes How to change font of String? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to change font of String?" Watch "How to change font of String?" New topic

How to change font of String?

Bob Zoloman
Ranch Hand

Joined: Jul 02, 2006
Posts: 72
Hi, I am trying to change the font, style, and size of a String so I can save the formatted output to a textFile. I tried to make a new Font object, but there is no setFont method on Strings to apply it to. Thanks in advance.
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
On what context are you writing them?
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24195

A text file has no format -- it's just text. To write formatted text to a file, you need to write a file format that supports... formatting. Options include HTML (lots of HTML libaries out there), PDF (the iText library) or RTF (iText again,) or PostScript (not sure what the best way to do this from Java is).

But you can't apply a style to a String -- it doesn't really make sense. You can write a String to a file, and also write the formatting information to the file -- but you first have to decide what kind of a file you're writing.

[Jess in Action][AskingGoodQuestions]
Bob Zoloman
Ranch Hand

Joined: Jul 02, 2006
Posts: 72
All I want to do is write text to a text file with a different font, and size. Notepad allows me to change fonts and sizes, so I'm assuming there must be some way to change the font of the String I want to output to the file.
Daniel Gagnon

Joined: Aug 27, 2006
Posts: 13
Notepad only let you pick the font you want to display the text but this font is not encoded in the file itself.
I agree. Here's the link:
subject: How to change font of String?
jQuery in Action, 3rd edition