Java Graphics Draw String paintOutline(Graphics g, String s, int textX, int textY, int thickness)

Here you can find the source of paintOutline(Graphics g, String s, int textX, int textY, int thickness)

Description

paint Outline

License

Open Source License

Declaration

public static void paintOutline(Graphics g, String s, int textX, int textY, int thickness) 

Method Source Code


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

import java.awt.*;

public class Main {
    public static Color[] darkGray = new Color[11];

    public static void paintOutline(Graphics g, String s, int textX, int textY, int thickness) {
        if (thickness > 10) {
            thickness = 10;/*from   w  w w. j  av a 2s.  c  om*/
        }

        if (thickness > 0) {
            g.setColor(getDarkGray(thickness));

            for (int i = -thickness; i <= thickness; i++) {
                for (int j = -thickness; j <= thickness; j++) {
                    if (i != 0 || j != 0) {
                        g.drawString(s, textX + i, textY + j);
                    }
                }
            }
        }

        g.setColor(Color.white);
        g.drawString(s, textX, textY);
    }

    private static Color getDarkGray(int thickness) {
        if (darkGray[thickness] == null) {
            darkGray[thickness] = new Color(64, 64, 64, 255 / thickness / thickness);
        }

        return darkGray[thickness];
    }
}

Related

  1. drawUnderlineCharAt(Graphics g, String text, int underlinedIndex, int x, int y)
  2. drawVerticalText(Graphics2D graphics, Font font, Dimension2D dimension, String text)
  3. drawVerticalTextCenter(Graphics2D g2, String str, int x, int y)
  4. drawWrappedText(Graphics2D g2, float x, float y, float width, String text)
  5. paintCenteredString(Graphics2D g, String str, Font font, int centerX, int centerY)
  6. paintShadowTitleFat(Graphics g, String title, int x, int y, Color frente, Color shadow, int desp)
  7. paintTextEffect(final Graphics2D g2d, final String s, final Color c, final int size, final double tx, final double ty, final boolean isShadow)
  8. paintTexture(BufferedImage pattern, BufferedImage template)