Here you can find the source of estimateWidth(Font font, String msg)
Parameter | Description |
---|---|
font | font used. |
msg | the message. |
public static int estimateWidth(Font font, String msg)
//package com.java2s; // the terms of the GNU General Public License as published by the Free Software Foundation; import javax.swing.*; import java.awt.*; public class Main { private static final JLabel FONT_LABEL = new JLabel(); /**//from w w w .j a v a 2s.c om * Estimates the width of the message being printed using the given font. * * @param font font used. * @param msg the message. * * @return width. */ public static int estimateWidth(Font font, String msg) { return FONT_LABEL.getFontMetrics(font).stringWidth(msg); } }