Java Draw Outline drawOutlinedStringSimple(Graphics2D g, String str, int x, int y)

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

Description

draw Outlined String Simple

License

Apache License

Declaration

public static int drawOutlinedStringSimple(Graphics2D g, String str, int x, int y) 

Method Source Code


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

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;

public class Main {
    public static int drawOutlinedStringSimple(Graphics2D g, String str, int x, int y) {
        Rectangle2D textArea = g.getFont().getStringBounds(str, g.getFontRenderContext());

        Color textColor = g.getColor();
        g.setColor(g.getBackground());/*from  ww  w.ja va 2 s .co m*/

        g.drawString(str, x + 1, y + 1);
        g.drawString(str, x + 1, y - 1);
        g.drawString(str, x - 1, y + 1);
        g.drawString(str, x - 1, y - 1);

        g.drawString(str, x + 1, y);
        g.drawString(str, x - 1, y);
        g.drawString(str, x, y - 1);
        g.drawString(str, x, y + 1);

        g.setColor(textColor);
        g.drawString(str, x, y);

        return (int) textArea.getWidth() + 1;
    }
}

Related

  1. drawOutlinedString(String s, int x, int y, Color fill, Color outline, Graphics g)
  2. drawOutlineText(Graphics graphics, String text, Color textColor, int x, int y, Color outlineColor, int outlineWidth)
  3. drawStringWithOutline(final Graphics g, final String str, int x, int y, Color fillColor, Color outlineColor)
  4. drawStringOutline(Graphics g, String s, int x, int y, Color c, Color cOutLine)