Here you can find the source of computeMultiLineStringDimension(FontMetrics oFontMetrics, String[] astr)
Parameter | Description |
---|---|
oFontMetrics | Font metrics used to size the string. |
astr | Multi-line string to be sized. |
public static final Dimension computeMultiLineStringDimension(FontMetrics oFontMetrics, String[] astr) throws IllegalArgumentException
//package com.java2s; /*//from w ww .j a v a 2s. c o m * Utilities.java * * Copyright 2000-2013 by Steven Soloff. * All rights reserved. * * 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 3 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, see <http://www.gnu.org/licenses/>. */ import java.awt.Dimension; import java.awt.FontMetrics; import javax.swing.SwingUtilities; public class Main { /** * Computes the dimensions of a multi-line string using the specified font. * * @param oFontMetrics Font metrics used to size the string. * @param astr Multi-line string to be sized. * * @return Dimensions of the specified string. * * @exception IllegalArgumentException If oFontMetrics or astr is null. */ public static final Dimension computeMultiLineStringDimension(FontMetrics oFontMetrics, String[] astr) throws IllegalArgumentException { ///////////////////////////////////////////////////////////////////// // VARIABLE DECLARATIONS // int nWidth, // Maximum width of the string nLines, // Number of lines in the string nI; // Loop control variable // // ///////////////////////////////////////////////////////////////////// // Make sure arguments are valid if (oFontMetrics == null || astr == null) throw new IllegalArgumentException(); // Compute the maximum width of the string for (nI = 0, nWidth = 0, nLines = astr.length; nI < nLines; nI++) nWidth = Math.max(nWidth, SwingUtilities.computeStringWidth(oFontMetrics, astr[nI])); // Return the dimensions of the string return (new Dimension(nWidth, oFontMetrics.getHeight() * astr.length)); } }