Here you can find the source of fontSize(Font f)
Parameter | Description |
---|---|
text | the string |
f | Font to use |
@SuppressWarnings(value = "deprecated") public static Dimension fontSize(Font f)
//package com.java2s; //License from project: Apache License import java.awt.*; public class Main { /**// w w w. j a v a 2s . c om * { method * * @param text the string * @param f Font to use * @return height + width * } * @name measureText * @function measure a text string in some font - * useful for non awt objects */ @SuppressWarnings(value = "deprecated") public static Dimension fontSize(Font f) { Toolkit g = Toolkit.getDefaultToolkit(); // defaultGraphics(); if (g == null) { return (new Dimension(10, 10)); } FontMetrics metrics = g.getFontMetrics(f); return (new Dimension(metrics.charWidth('W'), metrics.getHeight())); } }