Home » Desktop Java » awt » font » List all available font families

About Ilias Tsagklis

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

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.

(No Ratings Yet)
2 Comments Views Tweet it!

Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you our best selling eBooks for FREE!

 

1. JPA Mini Book

2. JVM Troubleshooting Guide

3. JUnit Tutorial for Unit Testing

4. Java Annotations Tutorial

5. Java Interview Questions

6. Spring Interview Questions

7. Android UI Design

 

and many more ....

 

Receive Java & Developer job alerts in your Area

 

2
Leave a Reply

avatar
2 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
2 Comment authors
Pistos KingShrikant Rana Recent comment authors
  Subscribe  
newest oldest most voted
Notify of
Shrikant Rana
Guest

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

Pistos King
Guest

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