How do I get the available font names?

package org.kodejava.awt;

import java.awt.Font;
import java.awt.GraphicsEnvironment;

public class FontNameList {
    public static void main(String[] args) {
        // Get all available fonts from GraphicsEnvironment
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        Font[] fonts = ge.getAllFonts();

        // Iterates all available fonts and get their name and family name
        for (Font font : fonts) {
            String fontName = font.getName();
            String familyName = font.getFamily();

            System.out.println("Font: " + fontName + "; family: " + familyName);
        }
    }
}

Here are some fonts name printed from the code snippet above:

Font: Agency FB; family: Agency FB
Font: Agency FB Bold; family: Agency FB
Font: Algerian; family: Algerian
Font: Arial; family: Arial
Font: Arial Black; family: Arial Black
Font: Arial Bold; family: Arial
Font: Arial Bold Italic; family: Arial
Font: Arial Italic; family: Arial
Font: Arial Narrow; family: Arial Narrow
Font: Arial Narrow Bold; family: Arial Narrow
...
Wayan

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.