font

List all available font families

With this tutorial we are going to see how to list all available font families in your environment using Java.

A font family refers to a set of font faces with a related typographic design. For example, the font faces in the Lucida Sans Typewriter family are Lucida Sans Typewriter Bold, and Lucida Sans Typewriter Regular etc. This example lists all available font family names in the system.

Basically to list all font families in Java:

  • Create a GraphicsEnvironment instance
  • Use its method getAvailableFontFamilyNames() that returns an String array containing all font names.

Let’s take a look at the code:

package com.javacodegeeks.snippets.desktop;

import java.awt.GraphicsEnvironment;

public class FontFamilyNames {

    public static void main(String[] args) {

   /**
    * A font family refers to a set of font faces with a related typographic design. 
    * For example, the font faces in the Lucida Sans Typewriter family are 
    * Lucida Sans Typewriter Bold, and Lucida Sans Typewriter Regular etc.
    * This example lists all available font family names in the system.
    * 
    * Note: J2SE 1.4 only supports True Type fonts
    */

  GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();

  String fontNames[] = ge.getAvailableFontFamilyNames();

  // Iterate the font family names

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

     System.out.println(fontNames[i]);

  }

    }

}

Example Output:

A&S Signwriter Andale Mono Angelic War Arial Arial Black Bitstream Charter Calligraphia One Century Schoolbook L Comic Sans MS Courier Courier 10 Pitch Courier New Cursor DejaVu Sans DejaVu Sans Condensed DejaVu Sans Light DejaVu Sans Mono DejaVu Serif DejaVu Serif Condensed Dialog DialogInput Dingbats East Syriac Adiabene East Syriac Ctesiphon Estrangelo Antioch Estrangelo Edessa Estrangelo Midyat Estrangelo Nisibin Estrangelo Nisibin Outline Estrangelo Quenneshrin Estrangelo Talada Estrangelo TurAbdin FifthLeg FreeMono FreeSans FreeSerif Georgia Goha-Tibeb Zemen Hershey Impact Liberation Mono Liberation Sans Liberation Serif Lucida Bright Lucida Sans Lucida Sans Typewriter Luxi Mono Luxi Sans Luxi Serif Monospaced Nimbus Mono L Nimbus Roman No9 L Nimbus Sans L Nimbus Sans L Condensed Qwigley SansSerif Serif Serto Batnan Serto Jerusalem Serto Jerusalem Outline Serto Kharput Serto Malankara Serto Mardin Serto Urhoy Standard Symbols L Syntha Times New Roman Trebuchet MS URW Bookman L URW Chancery L URW Gothic L URW Palladio L Utopia Verdana Webdings Yudit

 
This was an example on how to list the available font families.

Ilias Tsagklis

Ilias is a software developer turned online entrepreneur. He is co-founder and Executive Editor at Java Code Geeks.
Subscribe
Notify of
guest

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

2 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Shrikant Rana
5 years ago

very useful info.
I want to see all the font family list to show on a web page.

Pistos King
5 years ago

Thanks a lot for the amazing guide. I would check them right now.

Back to top button