Java FontMetrics stringDimension(Graphics g, Font f, String s)

Here you can find the source of stringDimension(Graphics g, Font f, String s)

Description

Returns the dimension of the specified string s in specified graphic and font environment.

License

Open Source License

Parameter

Parameter Description
g the graphic environment
f the font environment
s the string to display

Return

the dimension of the string

Declaration

public static Dimension stringDimension(Graphics g, Font f, String s) 

Method Source Code

//package com.java2s;

import java.awt.Dimension;

import java.awt.Font;
import java.awt.FontMetrics;

import java.awt.Graphics;

public class Main {
    /**//from   ww  w .  j a  v a  2 s.  c o m
     * Returns the dimension of the specified string <tt>s</tt> in specified
     * graphic and font environment.
     * 
     * @param g
     *            the graphic environment
     * @param f
     *            the font environment
     * @param s
     *            the string to display
     * @return the dimension of the string
     */
    public static Dimension stringDimension(Graphics g, Font f, String s) {
        FontMetrics fm = g.getFontMetrics(f);
        return new Dimension(fm.stringWidth(s), fm.getHeight());
    }
}

Related

  1. setSizedFont(Graphics g, String text, float maxFontSize, int maxWidth)
  2. shortenString(FontMetrics fm, String str, int maxWidth)
  3. splitStringWithLength(String s, int length, FontMetrics fm)
  4. splitText(String text, String delim, FontMetrics fontMetrics, int width)
  5. stringByTruncatingToFitInWidth(String s, int width, Graphics g, String truncatedSuffix)
  6. StringDimension(Graphics g, String text)
  7. wordWrap(String text, FontMetrics metrics, double width)
  8. wrapText(String text, int width, FontMetrics fontMetrics)