本文整理汇总了Java中java.awt.Component.getFontMetrics方法的典型用法代码示例。如果您正苦于以下问题:Java Component.getFontMetrics方法的具体用法?Java Component.getFontMetrics怎么用?Java Component.getFontMetrics使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.Component
的用法示例。
在下文中一共展示了Component.getFontMetrics方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getBorderInsets
import java.awt.Component; //导入方法依赖的package包/类
/**
* Reinitialize the insets parameter with this Border's current Insets.
* @param c the component for which this border insets value applies
* @param insets the object to be reinitialized
*/
public Insets getBorderInsets(Component c, Insets insets) {
if (!(c instanceof JPopupMenu)) {
return insets;
}
FontMetrics fm;
int descent = 0;
int ascent = 16;
String title = ((JPopupMenu)c).getLabel();
if (title == null) {
insets.left = insets.top = insets.right = insets.bottom = 0;
return insets;
}
fm = c.getFontMetrics(font);
if(fm != null) {
descent = fm.getDescent();
ascent = fm.getAscent();
}
insets.top += ascent + descent + TEXT_SPACING + GROOVE_HEIGHT;
return insets;
}
示例2: getFontMetrics
import java.awt.Component; //导入方法依赖的package包/类
/** Get the font-metrics for the given font.
* @param font font for which the metrics is being retrieved.
* @param c component that is used to retrieve the metrics in case it's
* not yet in the cache.
*/
public static synchronized FontMetrics getFontMetrics(Font f, Component c) {
Object fm = font2FM.get(f);
if (fm == null) {
fm = c.getFontMetrics(f);
font2FM.put(f, fm);
}
return (FontMetrics)fm;
}
示例3: isFixedWidth
import java.awt.Component; //导入方法依赖的package包/类
/**
* 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;
}
示例4: updateMetrics
import java.awt.Component; //导入方法依赖的package包/类
final void updateMetrics() {
Component host = getContainer();
Font f = host.getFont();
metrics = host.getFontMetrics(f); // Metrics for the default font.
tabSize = getTabSize() * metrics.charWidth('m');
}