Get Available Font Objects - Java 2D Graphics

Java examples for 2D Graphics:Font

Description

Get Available Font Objects

Demo Code

 
import java.applet.Applet;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.GraphicsEnvironment;
 
 
public class Main {
 
        public void paint(Graphics g){
                GraphicsEnvironment graphicsEnvironment =
                        GraphicsEnvironment.getLocalGraphicsEnvironment();
               //w  w w. ja va 2 s. c o m
                Font fonts[] = graphicsEnvironment.getAllFonts();
                int y = 20;
                for(int i=0; i < fonts.length; i++){
                        //print font names
                        g.drawString(fonts[i].getName(), 10, y);
                        y += 20;
                }
        }
}

Related Tutorials