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

17,033

Solution 1

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:

Solution 2

This site has got a lot information about filters and effects, I think the sourcecode of the application is also available.

Share:
17,033
Tom Neyland
Author by

Tom Neyland

@TomNeyland

Updated on June 06, 2022

Comments

  • Tom Neyland
    Tom Neyland almost 2 years

    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?