Here you can find the source of getAllStylesSameWidthsFontsFamillyName()
public static String[][] getAllStylesSameWidthsFontsFamillyName()
//package com.java2s; //License from project: Open Source License import java.awt.Font; import java.awt.FontMetrics; import java.awt.GraphicsEnvironment; import java.awt.Graphics2D; import java.util.ArrayList; import java.util.List; public class Main { private static Graphics2D g2d; private static int defaultFontSize = 14; /**/* w w w .ja v a 2 s. c o m*/ * @return String[0] is the SciNotes fonts and String[1] the non-SciNotes */ public static String[][] getAllStylesSameWidthsFontsFamillyName() { String[] fontFamilly = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames(); List<String> all = new ArrayList(); List<String> notAll = new ArrayList(); for (int i = 0; i < fontFamilly.length; i++) { if (isAllStylesSameWidths(fontFamilly[i])) { all.add(fontFamilly[i]); } else { notAll.add(fontFamilly[i]); } } return new String[][] { all.toArray(new String[0]), notAll.toArray(new String[0]) }; } /** * @param fontFamilly the font familly to test * @return true if each glyph has the same width in different styles */ public static boolean isAllStylesSameWidths(String fontFamilly) { return isAllStylesSameWidths(new Font(fontFamilly, Font.PLAIN, defaultFontSize)); } /** * @param font the font to test * @return true if each glyph has the same width in different styles */ public static boolean isAllStylesSameWidths(Font font) { int[] style = new int[] { Font.PLAIN, Font.BOLD, Font.ITALIC, Font.BOLD | Font.ITALIC }; FontMetrics fm = g2d.getFontMetrics(font.deriveFont(style[0])); int[] widths = fm.getWidths(); for (int i = 1; i < style.length; i++) { fm = g2d.getFontMetrics(font.deriveFont(style[i])); int[] arr = fm.getWidths(); // The range 33--126 corresponds to the usual characters in ASCII for (int j = 33; j < 126; j++) { if (arr[j] != widths[j]) { return false; } } } return true; } }