Get the Available Font Names Using Java

This Java tutorial shows how to get the list of available fonts on your computer using Java.

The first step is to get an instance of the GraphicsEnvironment.

//Get the local graphics environment
GraphicsEnvironment ge;
ge = GraphicsEnvironment.getLocalGraphicsEnvironment();

Next, you can get the list of font names from the instance of the GraphicsEnvironment.
//Get the font names from the graphics environment
String[] fontNames = ge.getAvailableFontFamilyNames();

Below is the complete example:
//Get the local graphics environment
GraphicsEnvironment ge;
ge = GraphicsEnvironment.getLocalGraphicsEnvironment();

//Get the font names from the graphics environment
String[] fontNames = ge.getAvailableFontFamilyNames();

for (int index = 0; index < fontNames.length; index++)
{
System.out.println(fontNames[index]);
}


0 comments:

Post a Comment