How do I determine the system's available fonts?
Author: Deron Eriksson
Description: This Java tutorial shows how to determine the system's available fonts.
Tutorial created using: Windows XP || JDK 1.6.0_10 || Eclipse JEE Ganymede SR1 (Eclipse 3.4.1)

The available font family names of the current system can be obtained via the getAvailableFontFamilyNames() method of the local GraphicsEnvironment. The local GraphicsEnvironment can be obtained via the GraphicsEnvironment.getLocalGraphicsEnvironment() method.

The GetAvailableFontNames class demonstrates this. The getAvailableFontFamilyNames method of GraphicsEnvironment returns a String array of the font family names. The GetAvailableFontNames class iterates over this String array and displays the font family names.

package com.cakes;

import java.awt.GraphicsEnvironment;

public class GetAvailableFontNames {

	public static void main(String[] args) {
		GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
		String[] fontFamilyNames = graphicsEnvironment.getAvailableFontFamilyNames();
		for (int i = 0; i < fontFamilyNames.length; i++) {
			System.out.println("Font Family Name #" + (i + 1) + ":" + fontFamilyNames[i]);