Java FontMetrics getLineHeight(Component c, int defaultHeight)

Here you can find the source of getLineHeight(Component c, int defaultHeight)

Description

Gets the line height for the font for the component

License

Open Source License

Parameter

Parameter Description
c the component
defaultHeight the default height if the font on the specified component is null

Return

the line height for the font for the component (or the passed in the default value if the font on the specified component is null)

Declaration

public static int getLineHeight(Component c, int defaultHeight) 

Method Source Code

//package com.java2s;

import java.awt.*;

public class Main {
    /**/*from w  w w  .  ja v a2  s.c  om*/
     * Gets the line height for the font for the component
     *
     * @param c             the component
     * @param defaultHeight the default height if the font on the specified component is null
     * @return the line height for the font for the component (or the passed in the default value if the font on the
     *         specified component is null)
     */
    public static int getLineHeight(Component c, int defaultHeight) {
        Font f = c == null ? null : c.getFont();
        if (f == null) {
            return defaultHeight;
        }
        FontMetrics fm = c.getFontMetrics(f);
        float h = fm.getHeight();

        h += fm.getDescent();

        return (int) h;
    }
}

Related

  1. getCenterOffset(Graphics g, Font f, char ch)
  2. getComponentAverageCharacterWidth(Component component)
  3. getConsoleFontMetrics(Font font)
  4. getLineBreakIndex(Graphics g, String text, int index, double maxWidth)
  5. getLineHeight(Component c, int defaultHeight)
  6. getLineHeight(Component component, int count)
  7. getLineHeight(FontMetrics fm)
  8. getLongestStringWidth(FontMetrics fm, String[] theStrings)
  9. getMaxFittingFontSize(Graphics g, Font font, String string, Dimension size)