Java Code Examples for java.awt.FontMetrics.getWidths()

The following are Jave code examples for showing how to use getWidths() of the java.awt.FontMetrics class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: incubator-netbeans   File: FontPanel.java   View Source Code Vote up 5 votes
/**
    * Return true if this font is fixed width.
    * Only the first 256 characters are considered.
    * @param font
    * @return true if this font is fixed width.
    */
   private static boolean isFixedWidth(Component context, Font font) {
FontMetrics metrics = context.getFontMetrics(font);
int[] widths = metrics.getWidths();
int Swidth = widths[0];
for (int cx = 1; cx < widths.length; cx++) {
    int width = widths[cx];
    if (width == 0) {
	continue;
    } else if (Swidth != width) {
	return false;
    }
}
return true;
   }