ListFonts

Map fontFaceNames = new HashMap();

// Get all available font faces names
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
Font[] fonts = ge.getAllFonts();

// Process each font
for (int i=0; i<fonts.length; i++) {
    // Get font's family and face
    String familyName = fonts[i].getFamily();
    String faceName = fonts[i].getName();

    // Add font to table
    java.util.List list = (java.util.List)fontFaceNames.get(familyName);
    if (list == null) {
        list = new ArrayList();
        fontFaceNames.put(familyName, list);

    }
    list.add(faceName);
}

// Replace the face name lists with string arrays,
// which are more compact and convenient to use
for (Iterator it=fontFaceNames.keySet().iterator(); it.hasNext(); ) {
    String familyName = (String)it.next();
    java.util.List list = (java.util.List)fontFaceNames.get(familyName);
    fontFaceNames.put(familyName, list.toArray(new String[list.size()]));
}


// Use the table
String[] faces = (String[])fontFaceNames.get("Verdana");

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.