Get Available Font Family Names Example
- /*
- Get Available Font Family Names Example
- This java example shows how to get available font family names using
- getAvailableFontFamilyNames method of GraphicsEnvironment class.
- */
- import java.applet.Applet;
- import java.awt.Graphics;
- import java.awt.GraphicsEnvironment;
- /*
- <applet code="GetAvailableFonts" width=200 height=200>
- </applet>
- */
- public class GetAvailableFonts extends Applet{
- public void paint(Graphics g){
- /*
- * To get an object of GraphicsEnvironment, use
- * static GraphicsEnvironment getLocalGraphicsEnvironment()
- * method of GraphicsEnvironment class.
- *
- * This is a static method.
- */
- GraphicsEnvironment graphicsEnvironment =
- GraphicsEnvironment.getLocalGraphicsEnvironment();
- /*
- * To get available font family names use,
- * String[] getAvailableFontFamilyNames()
- * method of GraphicsEnvironment class.
- *
- * This method returns an array of strings
- * containing names of available font families.
- */
- String fontNames[] = graphicsEnvironment.getAvailableFontFamilyNames();
- int y = 20;
- for(int i=0; i < fontNames.length; i++){
- //print font names
- g.drawString(fontNames[i], 10, y);
- y += 20;
- }
- }
- }
Example Output




