Java Swing Font Metrics stringWidth(JComponent c, FontMetrics fm, String string)

Here you can find the source of stringWidth(JComponent c, FontMetrics fm, String string)

Description

Returns the width of the passed in String.

License

Open Source License

Parameter

Parameter Description
c JComponent that will display the string, may be null
fm FontMetrics used to measure the String width
string String to get the width of

Return

the int

Declaration

public static int stringWidth(JComponent c, FontMetrics fm, String string) 

Method Source Code

//package com.java2s;
/*/* w  w w.  ja va  2 s . co  m*/
 * Copyright (C) 2015 Jack Jiang(cngeeker.com) The BeautyEye Project. 
 * All rights reserved.
 * Project URL:https://github.com/JackJiang2011/beautyeye
 * Version 3.6
 * 
 * Jack Jiang PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 * 
 * MySwingUtilities2.java at 2015-2-1 20:25:40, original version by Jack Jiang.
 * You can contact author with jb2011@163.com.
 */

import java.awt.FontMetrics;

import javax.swing.JComponent;

public class Main {
    /**
     * Returns the width of the passed in String.
     *
     * @param c JComponent that will display the string, may be null
     * @param fm FontMetrics used to measure the String width
     * @param string String to get the width of
     * @return the int
     */
    public static int stringWidth(JComponent c, FontMetrics fm, String string) {
        return fm.stringWidth(string);
    }
}

Related

  1. getTabbedTextOffset(Segment s, FontMetrics metrics, int x0, int x, TabExpander e, int startOffset)
  2. getTabbedTextWidth(Segment s, FontMetrics metrics, int x, TabExpander e, int startOffset)
  3. getTextBounds(FontMetrics fm, String s)
  4. getWidthOfText(FontMetrics fontMetrics, String text)
  5. layoutMultilineCompoundLabel(JComponent c, FontMetrics fm, String text, Icon icon, int verticalAlignment, int horizontalAlignment, int verticalTextPosition, int horizontalTextPosition, Rectangle viewR, Rectangle iconR, Rectangle textR, int textIconGap, int minLines, int maxLines)
  6. wrapString(String s, FontMetrics fm, int width)
  7. wrapText(String text, FontMetrics metrics, int maxWidth)