Basic HTML version of Foils prepared 18 May 97

Foil 8 The java.awt.Font and FontMetrics Classes

From Java Tutorial - Spring 1997 Part 3:Graphics and the Abstract Windowing Toolkit Peking Tutorial, Web Certificate -- Spring-Summer 1997. by Nancy J. McCracken,Geoffrey C. Fox


1 Graphicsinstance.setFont(particularFont) will set the current Font in the instance Graphicsinstance of graphics class to the value particularFont of class Font. There are several other such Font related methods in the Graphics class
2 The class Font has an important constructor used as in
3 Font particularFont = new Font("TimesRoman",Font.PLAIN,36);
4 where one can use Courier Helvetica etc. instead of Time Roman
5 Font.PLAIN, Font.BOLD, Font.ITALIC are possible text styles
6 FontMetrics fm = getFontMetrics(particularFont); // allows one to find out about the font, such as leading, aspect, etc.
7 fm.stringWidth("text"); // returns pixel width of string "text"
8 fm.getHeight(); // returns total height of one line of Font

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 Thu Jan 8 1998