Java Swing Font Metrics computeStringWidth(FontMetrics fontMetrics, String str)

Here you can find the source of computeStringWidth(FontMetrics fontMetrics, String str)

Description

compute String Width

License

Open Source License

Declaration

public static int computeStringWidth(FontMetrics fontMetrics, String str) 

Method Source Code


//package com.java2s;
/* //from  w w  w  .  ja v  a  2 s .  com
 * @(#)StringUtil.java 1.0 2004-10-11
 *
 * Copyright 2005 UFIDA Software Co. Ltd. All rights reserved.
 * UFIDA PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

import java.awt.FontMetrics;

public class Main {

    public static int computeStringWidth(FontMetrics fontMetrics, String str) {
        if (str == null || str.length() <= 0)
            return 0;
        int width = 10 + javax.swing.SwingUtilities.computeStringWidth(fontMetrics, str);
        int bytesLen = str.getBytes().length;
        if (bytesLen >= 10)
            width += (bytesLen - 10) * 2 + 5;
        return width;
    }
}

Related

  1. clipString(JComponent c, FontMetrics fm, String string, int availTextWidth)
  2. clipString(JComponent c, FontMetrics fm, String string, int availTextWidth)
  3. clipStringIfNecessary(JComponent c, FontMetrics fm, String string, int availTextWidth)
  4. clipText(FontMetrics fm, String val, int width)
  5. computeMultiLineStringDimension(FontMetrics oFontMetrics, String[] astr)
  6. drawLine(Graphics g, FontMetrics fm, Rectangle rect, String text, int hAlign, int y, int mnemonic)
  7. getBreakLocation(Segment s, FontMetrics metrics, int x0, int x, TabExpander e, int startOffset)
  8. getClippedText(String text, FontMetrics fm, int maxWidth)
  9. getClippedText(String text, FontMetrics fm, int maxWidth)