Here you can find the source of drawString(Graphics2D g, String string, int x, int y, boolean includeOutline)
Parameter | Description |
---|---|
g | the Graphics2D to paint to. |
string | the string to paint |
x | the x-coordinate of the string location |
y | the y-coordinate of the string location |
includeOutline | whether to paint a white outline |
public static void drawString(Graphics2D g, String string, int x, int y, boolean includeOutline)
//package com.java2s; /*/*www . ja v a2 s .c om*/ * @(#)BlogHelper.java * * $Date: 2014-11-27 07:50:51 +0100 (Do, 27 Nov 2014) $ * * Copyright (c) 2014 by Jeremy Wood. * All rights reserved. * * The copyright of this software is owned by Jeremy Wood. * You may not use, copy or modify this software, except in * accordance with the license agreement you entered into with * Jeremy Wood. For details see accompanying license terms. * * This software is probably, but not necessarily, discussed here: * https://javagraphics.java.net/ * * That site should also contain the most recent official version * of this software. (See the SVN repository for more details.) */ import java.awt.AlphaComposite; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Font; import java.awt.Graphics2D; import java.awt.Shape; public class Main { /** Draw a string in Verdana size 14. * @param g the Graphics2D to paint to. * @param string the string to paint * @param x the x-coordinate of the string location * @param y the y-coordinate of the string location * @param includeOutline whether to paint a white outline */ public static void drawString(Graphics2D g, String string, int x, int y, boolean includeOutline) { Font font = (new Font("Verdana", 0, 14)); if (includeOutline) { Shape textShape = font.createGlyphVector( g.getFontRenderContext(), string).getOutline(x, y); g.setComposite(AlphaComposite.SrcOver); if (includeOutline) { g.setStroke(new BasicStroke(3, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); g.setColor(Color.white); g.draw(textShape); } g.setColor(Color.black); g.fill(textShape); } else { g.setFont(font); g.setColor(Color.black); g.drawString(string, x, y); } } }