This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to change font of String?

 
Bob Zoloman
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On what context are you writing them?
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bob Zoloman
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Notepad only let you pick the font you want to display the text but this font is not encoded in the file itself.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic