Java Draw String drawString(Graphics2D g, String string, int x, int y)

Here you can find the source of drawString(Graphics2D g, String string, int x, int y)

Description

draw String

License

Apache License

Declaration

public static void drawString(Graphics2D g, String string, int x, int y) 

Method Source Code


//package com.java2s;
/*/*from ww  w  . j  a  v  a  2s .  c o m*/
 * Copyright 2005 Tom Gibara
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
    
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 */

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.font.GlyphVector;
import java.awt.geom.AffineTransform;

public class Main {
    public static void drawString(Graphics2D g, String string, int x, int y) {
        AffineTransform identity = new AffineTransform();
        g.setTransform(identity);
        g.setColor(Color.BLACK);
        Font font = Font.decode("Arial-BOLD-18");
        GlyphVector vector = font.createGlyphVector(g.getFontRenderContext(), string);
        Shape shape = vector.getOutline();
        g.setStroke(new BasicStroke(3));
        g.setFont(font);
        g.translate(x, y + g.getFontMetrics().getAscent());
        g.draw(shape);
        g.setColor(Color.WHITE);
        g.fill(shape);
        g.setTransform(identity);
    }
}

Related

  1. drawString(Graphics g, String text, int underlinedChar, int x, int y)
  2. drawString(Graphics g, String text, int x, int y)
  3. drawString(Graphics g2, String string, int x, int y, Font font, Color color)
  4. drawString(Graphics2D g, String s, int x, int y, int width)
  5. drawString(Graphics2D g, String string, double x, double y, Color color)
  6. drawString(Graphics2D g, String string, int x, int y, boolean includeOutline)
  7. drawString(Graphics2D g2, String str, int x, int y, int halign, int valign)
  8. drawString(Graphics2D gfx, String text, int x, int y)
  9. drawString(Graphics2D graphics, String text, double x, double y, boolean centerHorizontal, boolean centerVertical, Color backgroundColor)