Here you can find the source of stringWidth(JComponent c, FontMetrics fm, String string)
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 |
public static int stringWidth(JComponent c, FontMetrics fm, String string)
//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); } }