Example usage for javax.swing JLabel getFontMetrics

List of usage examples for javax.swing JLabel getFontMetrics

Introduction

In this page you can find the example usage for javax.swing JLabel getFontMetrics.

Prototype

public FontMetrics getFontMetrics(Font font) 

Source Link

Document

Gets the FontMetrics for the specified Font.

Usage

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);
}