Here you can find the source of fontSize(Font f)
Parameter | Description |
---|---|
text | the string |
f | Font to use |
public static Dimension fontSize(Font f)
//package com.java2s; //License from project: Apache License import java.awt.*; import java.awt.geom.*; import java.awt.font.*; public class Main { /**// w ww .j av a 2 s .c o m * { 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 */ public static Dimension fontSize(Font f) { Toolkit g = Toolkit.getDefaultToolkit(); // defaultGraphics(); if (g == null) { return (new Dimension(10, 10)); } FontRenderContext frc = new FontRenderContext(null, false, false); Rectangle2D bounds = f.getStringBounds("W", frc); double height = bounds.getHeight(); double width = bounds.getWidth(); return (new Dimension((int) width, (int) height)); } }