Meaningless Drivel is fun!*
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
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to get a String width(pixel or Metric)