List of usage examples for javax.swing JLabel getFontMetrics
public FontMetrics getFontMetrics(Font font)
FontMetrics
for the specified Font
. From source file:pt.webdetails.cgg.scripts.BaseScope.java
public static Object getTextHeightCGG(Context cx, Scriptable thisObj, Object[] args, Function funObj) { // String text = Context.toString(args[0]); String fontFamily = Context.toString(args[1]); String fontSize = Context.toString(args[2]).trim(); String fontStyle = "normal"; String fontWeight = "normal"; if (args.length > 3) { fontStyle = Context.toString(args[3]); if (args.length > 4) { fontWeight = Context.toString(args[4]); }//from w w w. j a va 2 s . c om } Font ffont = getFont(fontFamily, fontSize, fontStyle, fontWeight); JLabel label = new JLabel(); FontMetrics fMetric = label.getFontMetrics(ffont); int height = fMetric.getHeight(); return Context.toNumber(height); }