Java Folder Size Get fontSize(Font f)

Here you can find the source of fontSize(Font f)

Description

{ method

License

Apache License

Parameter

Parameter Description
text the string
f Font to use

Return

height + width }

Declaration

public static Dimension fontSize(Font f) 

Method Source Code


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

Related

  1. emSize(Font font, double em)
  2. folderSize(File directory)
  3. folderSize(File directory)
  4. folderSize(File directory)
  5. fontSize(Font f)
  6. setFileChooserFont(Component[] comp, int newFontSize)
  7. setFontOfPixelHeight(Graphics2D g, int style, double targetSize)
  8. setFontSize(Component c, float size)
  9. setFontSize(final C component, final int fontSize)