How can I create a drop shadow, inner glow and outer glow in Java Swing?

Tom Neyland picture Tom Neyland · Jul 13, 2010 · Viewed 16.9k times · Source

I am generating some images using the Graphics2D interface, and occasionally I'd like to be able to draw some text on the image and apply to it effects like the ones in Adobe Photoshop.

Right now to generate a 'shadow' on the text I am drawing the text twice, once in the original color, and once in black with a slight (1px) x&y offset. Unfortunately this is overly simplistic as I need more control over the shadow (opacity,size, spread).

As for Inner Glows and Outer Glows, I am not really sure where to start; a mask/gradient paint/alpha blending?

Is there a Java library for producing these types of effects? If not how would you go about creating these effects?

Answer

Jay Askren picture Jay Askren · Jul 27, 2010

I would highly recommend the book Filthy Rich Clients. Chapter 16 talks about drop shadows. You also might be interested in the this blog post. Chapter 17 talks about the glowing effect. There is example code on the website for both. The rest of the book is well worth reading as well. I couldn't put the book down when I read it. There are many other fun effects explained and demonstrated in the book.

The jhlabs site is also a good site, as mentioned.

Edit:

For a library, I would look at Painters in the SwingX library. Here are several tutorials: