Home Java Java-get-example Java get available Font



Java get available Font
Posted on: November 1, 2008 at 12:00 AM
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) {
  System.out.println(f.getFontName());
  }
  }
}

Output will be displayed as:

Download Source Code

Related Tags for Java get available Font:
ciogetfontthisaitolearneareilsectioninnthowsislleaarvassthavabablono


More Tutorials from this section

Ask Questions?    Discuss: Java get available Font  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.