How do I get the available font names?

Category: java.awt, viewed: 665 time(s).
 
package org.kodejava.example.awt;
 
import java.awt.Font;
import java.awt.GraphicsEnvironment;
 
public class FontNameList {
    public static void main(String[] args) {
        //
        // Get all available fonts from GraphicsEnvironment
        //
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        Font[] fonts = ge.getAllFonts();
        
        //
        // Iterates all available fonts and get their name and family name
        //
        for (Font font : fonts) {
            String fontName = font.getName();
            String familyName = font.getFamily();
            
            System.out.println("Font: " + fontName + "; family: " + familyName);
        }
    }
}
 
 
Bookmark this example!  

Most Viewed Examples

Google

100 Top & Latest


eXTReMe Tracker
visitor stats