Basic HTML version of Foils prepared Sept 21 1998

Foil 7 The java.awt.Font and FontMetrics Class

From Java Tutorial 98- 3: Graphics and the Abstract Windowing Toolkit NAVO Tutorial -- Sept 23 1998. by Geoffrey C. Fox, Nancy McCracken

FontMetrics example for Foil 7
1 Graphicsinstance.setFont(particularFont) will set the current Font in the instance Graphicsinstance of the Graphics class to the value particularFont of class Font.
2 The class Font has an important constructor used as in
3 Font MyFont = new Font("TimesRoman", Font.PLAIN ,36);
  • where one can also use Courier, Helvetica, ZapfDingbats, . . ., Monospaced, Serif, SansSerif, Dialog
  • Font.PLAIN, Font.BOLD, Font.ITALIC are possible text styles
4 FontMetrics fm = getFontMetrics(particularFont); // allows one to find out about the font
  • fm.stringWidth("text"); // returns pixel width of string "text"
  • fm.getHeight(); // returns total height of highest Font character
  • getAscent(),
  • getDescent(),
  • getLeading(),
5
6 Drawstring uses leftmost baseline point as (x,y)
7 Nancy
8 leading
9 ascent
10 descent
11 baseline
12 }
13 height

in Table To:


© Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Sat Nov 28 1998