how-to

Graphics

How to get throught all fonts

For this sample you must use:

import java.awt.*;

This sample code lists all available fonts. The instance of class java.awt.Font contains more detail informations about a font.

/* -- get all fonts */>

Font[] fonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();

/* -- go throught fonts and get more informations */

for ( int i = 0; i < fonts.length; i++ ) {

  //if ( ! fonts[i].getFamily().toLowerCase().startsWith( "cour") ) continue;

  System.out.println( fonts[i].getFontName() + " [" + fonts[i].getFamily() + "]" );
}

The output could be:

...
Arial Unicode MS [Arial Unicode MS]
Baskerville Old Face [Baskerville Old Face]
Bauhaus 93 [Bauhaus 93]
Bell MT [Bell MT]
Bell MT kurzíva [Bell MT]
Bell MT tučné [Bell MT]
...