Share on Google+Share on Google+

Java get available Font

In this section, you will learn how to get the available font.

Java get available Font


In this section, you will learn how to get the available font.

In order to retrieve all the available fonts, we have used the AWT package. The class GraphicsEnvironment describes the collection of all the available GraphicsDevices and Font objects.

getAllFonts()- This is the method of class GraphicsEnvironment. It returns an array of fonts available in the GraphicsEnvironment. 

getFontName()- This is the method of Font class. It returns the font name.

Here is the code of GetAvailableFont .java

import java.awt.*;
public class GetAvailableFont {
  public static void main(String[] a) {
  GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
  Font[] fonts = ge.getAllFonts(); 
  for (Font f : fonts) {

Output will be displayed as:

Download Source Code



Posted on: November 1, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Discuss: Java get available Font  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
October 28, 2013
Setting font

I am making a text editor in java and i want all fonts available in windows to be displayed in a list.. please tell me how could i do this... also tell me how to change the font of the text in the text area by selecting a font in that list.....