Return to Unit Menu | Java Main Page | | Terms of Use

Text Properties

Not only can you print text messages in a graphic display, you can also control the font, style and size of the printed text.


We will be controlling the font name, the font style (PLAIN, BOLD, ITALIC), and the font size.  Check out these examples:

Font timesBold16 = new Font("Times New Roman", Font.BOLD, 16);

Font arialBolditalic12 = new Font("Arial", Font.BOLD + Font.ITALIC, 12);

The names of the fonts will depend upon the computer running the program.  There is Java code that will tell you which font names are available on your computer.

String [ ] MyFontNames = Toolkit.getDefaultToolkit( ) . getFontList( );
for (int x = 0; x < MyFontNames.length; x++)


Sample coding using Font class:

Font courierBold10 = new Font("Courier", Font.BOLD, 10);
g.drawString("Java Rules!!!", 120, 120);



Return to Unit Menu | Java Main Page | | Terms of Use