Home Java Java-get-example Java get available Font
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

Java get available Font

Advertisement
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

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  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.

Posted on: November 1, 2008

Related Tutorials

Ask Questions?    Discuss: Java get available Font  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
akshay
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.....
DMCA.com