Java Font Text Width getTextWidth(String text, Graphics g, String newLineSplit)

Here you can find the source of getTextWidth(String text, Graphics g, String newLineSplit)

Description

get Text Width

License

Open Source License

Declaration

public static int getTextWidth(String text, Graphics g, String newLineSplit) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.awt.Graphics;

public class Main {
    public static int getTextWidth(String text, Graphics g, String newLineSplit) {
        int width = 0;
        String[] lines = text.split(newLineSplit);
        for (String line : lines) {
            int w = g.getFontMetrics().stringWidth(line);
            if (w > width) {
                width = w;/*from www  .j  ava  2s. co  m*/
            }
        }
        return width;
    }
}

Related

  1. getStringWidth(Graphics2D g2d, String info, Font font)
  2. getStringWidth(String loginID, Font font)
  3. getStringWidth(String s, FontMetrics fm)
  4. getStringWidth(String str, java.awt.Font font)
  5. getTextForWidth(double bboxWth, String txt, Font font)
  6. getWidth(String s, Graphics g)
  7. getWidthForText(String txt, Font font)
  8. getWidthOfDots(FontMetrics fontMetrics)
  9. setFixedWidthFont(Component comp)