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.
Example 1
Project: incubator-netbeans   File:   Source Code and License 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) {
    } else if (Swidth != width) {
	return false;
return true;