Java Font Text Width getStringWidth(String loginID, Font font)

Here you can find the source of getStringWidth(String loginID, Font font)

Description

get String Width

License

Open Source License

Declaration

public static int getStringWidth(String loginID, Font font) 

Method Source Code

//package com.java2s;
/*//w  w w .  j a va2s.  com
 * Copyright (C) 2016 Open Source Parking, Inc.(www.osparking.com)
 *
 * 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.Font;

import java.awt.font.FontRenderContext;
import java.awt.geom.AffineTransform;

public class Main {
    public static int getStringWidth(String loginID, Font font) {
        AffineTransform affinetransform = new AffineTransform();
        FontRenderContext frc = new FontRenderContext(affinetransform, true, true);
        return (int) ((font.getStringBounds(loginID, frc)).getWidth());
    }
}

Related

  1. getStringWidth(Font font, String text)
  2. getStringWidth(FontMetrics f, String s)
  3. getStringWidth(Graphics g, Font font, String x)
  4. getStringWidth(Graphics2D g2, final String str)
  5. getStringWidth(Graphics2D g2d, String info, Font font)
  6. getStringWidth(String s, FontMetrics fm)
  7. getStringWidth(String str, java.awt.Font font)
  8. getTextForWidth(double bboxWth, String txt, Font font)
  9. getTextWidth(String text, Graphics g, String newLineSplit)