This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

does java have a class to find string width?

 
Tina Long
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does anyone have any suggestions on what I could do to figure out the width of a string?

Ex:
If I have two strings:
"WHOOO HOOO"
vs
"ITTY BITTY"

Both strings have the same number of letters however when I use a font that is not fixed width - then the second string takes up less room when typed. Is there anything out there that will help me find the width of the string?

I need to take in account the font used and the string written - I've been looking at the Font class - but not finding what I need. Thoughts anyone?
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
 
Seb Mathe
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at the FontMetrics class.
 
Tina Long
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks - I believe that will work for me! YAY!

How did you know that? Is it experience? I searched and read and I finally gave up and asked. Thanks for your quick response.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Experience. FontMetrics is one of the original few hundred API classes, from way back in the Java 1.0 days when it was possible to know about all the classes in the API.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic