Skip to content

Java Font List

Here’s a program that lists fonts available in your JVM. You can also set the environment variable JAVA_FONTS to specify the font directory.

import java.awt.GraphicsEnvironment;

public class ListFonts {
	public static void main(String args[]){
		GraphicsEnvironment e = GraphicsEnvironment.getLocalGraphicsEnvironment();
		for(String font:e.getAvailableFontFamilyNames()){
			System.out.println(font);
		}
	}
}

By using pipes you can count how many fonts you have:

java ListFonts|wc -l

On my Ubuntu machine here I got 556 because I use those excellent, free and indispensable Larabie Fonts.

For looking up for a font with “sans” in its name, using a case insensitive grep:

java ListFonts|grep -i “sans”

I get a list like this:

DejaVu Sans
DejaVu Sans Condensed
DejaVu Sans Light
DejaVu Sans Mono
FreeSans

Published inenglish