Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to get a String width(pixel or Metric)

 
daniel xiao
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to get a String width(pixel or Metric)??
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic