Toolkit.getFontMetrics(Font) has been deprecated in Java 2. What do I use instead?

John Zukowski

The java.awt.font.LineMetrics class provides the necessary information. Just ask the Font for the specific LineMetrics with getLineMetrics(). You'll need to know the string and the FontRenderContext, where the context is acquired from the Graphics2D object.


Font font = ...
FontRenderContext context = g2d.getFontRenderContext()
LineMetrics metrics = font.getLineMetrics("jGuru", context);
0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact