Java Swing Font Metrics getFontMetrics(Font font)

Here you can find the source of getFontMetrics(Font font)

Description

Gets the font metrics for the specified font.

License

Open Source License

Parameter

Parameter Description
font The font for which font metrics is to be obtained.

Return

the FontMetrics

Declaration

public static FontMetrics getFontMetrics(Font font) 

Method Source Code

//package com.java2s;
import java.awt.Font;
import java.awt.FontMetrics;
import javax.swing.JPanel;

public class Main {
    /**//  w w  w. j ava  2  s.c o m
     * A JPanel from which we can gain font metrics.
     */
    private static final JPanel DUMMY_PANEL = new JPanel();

    /**
     * Gets the font metrics for the specified font.
     * 
     * @param font
     *                The font for which font metrics is to be obtained.
     * @return the FontMetrics
     */
    public static FontMetrics getFontMetrics(Font font) {
        // return Toolkit.getDefaultToolkit().getFontMetrics(font);
        return DUMMY_PANEL.getFontMetrics(font);
    }
}

Related

  1. getClippedText(String text, FontMetrics fm, int maxWidth)
  2. getClippedText(String text, FontMetrics fm, int maxWidth)
  3. getClippedText(String text, FontMetrics fm, int maxWidth)
  4. getDefaultLabelFontMetrics()
  5. getFontMetrics(final JComponent c, final Graphics g)
  6. getFontMetrics(Font font)
  7. getFontMetrics(Font font)
  8. getFontMetrics(JComponent c, Graphics g)
  9. getFontMetrics(JComponent c, Graphics g)