!7 import java.awt.font.*; p { BufferedImage img = newBufferedImage(400, 400, Color.blue); Graphics2D g = imageGraphics(img); g.setFont(sansSerifBold(20)); paintTextWithOutline(g); g.dispose(); showImage(img); } static void paintTextWithOutline(Graphics g) { String text = "BOMBS [BAD]"; Color outlineColor = Color.black; Color fillColor = Color.yellow; BasicStroke outlineStroke = new BasicStroke(2.0f); if (g instanceof Graphics2D) { Graphics2D g2 = (Graphics2D) g; g.translate(100, 100); // remember original settings Color originalColor = g2.getColor(); Stroke originalStroke = g2.getStroke(); RenderingHints originalHints = g2.getRenderingHints(); // create a glyph vector from your text GlyphVector glyphVector = g.getFont().createGlyphVector(g2.getFontRenderContext(), text); // get the shape object Shape textShape = glyphVector.getOutline(); // activate anti aliasing for text rendering (if you want it to look nice) g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g2.setColor(outlineColor); g2.setStroke(outlineStroke); g2.draw(textShape); // draw outline g2.setColor(fillColor); g2.fill(textShape); // fill the shape // reset to original settings after painting g2.setColor(originalColor); g2.setStroke(originalStroke); g2.setRenderingHints(originalHints); } }