Here you can find the source of getCharsWidth(Font font, char[] chars, int offset, int length)
Parameter | Description |
---|---|
chars | The char array to get the width for. |
offset | The offset where to start. |
length | The length of the measure. |
font | The font being the base of the measure. |
public static int getCharsWidth(Font font, char[] chars, int offset, int length)
//package com.java2s; /*//from w w w.ja v a2 s . c o m * TV-Browser * Copyright (C) 04-2003 Martin Oberhauser (martin_oat@yahoo.de) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * CVS information: * $RCSfile$ * $Source$ * $Date: 2010-11-14 17:44:44 +0100 (Sun, 14 Nov 2010) $ * $Author: bananeweizen $ * $Revision: 6823 $ */ import java.awt.Font; import java.awt.FontMetrics; import javax.swing.JLabel; public class Main { /** The helper label. */ private static final JLabel HELPER_LABEL = new JLabel(); /** * Gets the width of the specified char array. * * @param chars * The char array to get the width for. * @param offset * The offset where to start. * @param length * The length of the measure. * @param font * The font being the base of the measure. * @return the width of the specified char array. */ public static int getCharsWidth(Font font, char[] chars, int offset, int length) { if (chars == null) { return 0; } FontMetrics metrics = HELPER_LABEL.getFontMetrics(font); return metrics.charsWidth(chars, offset, length); } }