Java Graphics Draw Multiline String drawMultiLineText(String text, Graphics G, int x, int y)

Here you can find the source of drawMultiLineText(String text, Graphics G, int x, int y)

Description

draw Multi Line Text

License

Apache License

Declaration

public static void drawMultiLineText(String text, Graphics G, int x, int y) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.awt.*;

import java.util.*;

public class Main {
    public static void drawMultiLineText(String text, Graphics G, int x, int y) {
        FontMetrics metrics = G.getFontMetrics();

        StringTokenizer str = new StringTokenizer(text, "\n\r");
        int height = y;

        while (str.hasMoreTokens()) {
            String token = str.nextToken();

            G.drawString(token, x, height + metrics.getAscent());
            height += (metrics.getAscent() + metrics.getLeading());
        }//from w w  w.j  a v a2s  .c om
    }
}

Related

  1. draw(String _str, Graphics2D _g2, int _nX0, int _nY0, int _nX1, int _nY1)
  2. drawMultilineString(Graphics g, String s, int alignment, Rectangle r, boolean print)
  3. drawMultilineText(final Graphics2D gc, final int x, int y, final String text)
  4. drawRightMultiLineText(String text, Graphics G, int x, int y)
  5. drawString(Graphics g, String s, int x, int y)
  6. drawStringBiggest(final Graphics2D g2d, final Dimension dim, final String drawString)
  7. drawStringUnderlineCharAt(Graphics g, String s, int underlinedIndex, int x, int y)