• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to change font of String?

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
On what context are you writing them?
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic