Java Swing Tutorial - Java GraphicsEnvironment .getAllFonts ()








Syntax

GraphicsEnvironment.getAllFonts() has the following syntax.

public abstract Font [] getAllFonts()

Example

In the following code shows how to use GraphicsEnvironment.getAllFonts() method.

import java.awt.Font;
import java.awt.GraphicsEnvironment;
/*from www . jav  a2  s  .  c o  m*/
public class Main {

  public static void main(String[] args) throws Exception {
    Font[] fonts  = GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();
    for (int i = 0; i < fonts.length; i++) {
      System.out.print(fonts[i].getFontName() + " : ");
      System.out.print(fonts[i].getFamily() + " : ");
      System.out.print(fonts[i].getName());
      System.out.println();
    }
  }
}

The code above generates the following result.