This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes How to get a String width(pixel or Metric) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to get a String width(pixel or Metric)" Watch "How to get a String width(pixel or Metric)" New topic
Author

How to get a String width(pixel or Metric)

daniel xiao
Greenhorn

Joined: Jul 04, 2003
Posts: 12
How to get a String width(pixel or Metric)??
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

FontMetrics.stringWidth( String ) returns an int width (I think this is in pixels? )

You can get the FontMetrics object through a Graphics object's getFontMetrics() or getFontMetrics( Font ) methods.


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
 
 
subject: How to get a String width(pixel or Metric)