Java Tips Weblog

  • Blog Stats

    • 1,759,499 hits
  • Categories

  • Archives

Alpha Icons

Posted by Darryl Burke on August 22, 2010

These Alpha Icons wrap any Icon and paint it with the specified transparency. As Swing does not play well with an Icon that is not itself an ImageIcon but requires to show an animated GIF, two implementations are provided: AlphaIcon, which is good for wrapping any Icon, including an ImageIcon with a static image, and AlphaImageIcon which extends ImageIcon and can provide transparency for an ImageIcon that holds an animated image.

Each implementation provides a constructor that takes two parameters: the icon to be wrapped, and the opacity, a float value in the range 0.0F (fully transparent) to 1.0F (fully opaque).

When combined with Rob’s CompoundIcon with a Z_AXIS alignment, AlphaIcon and AlphaImageIcon allow you to overlay one Icon on another with the bottom Icon showing through. Multisort Table Header Cell Renderer showcases the use of AlphaIcons with varying transparency to indicate multiple sort orders in the header of a JTable.

Get The Code

See Also

Compound Icon
Multisort Table Header Cell Renderer

Related Reading

Java API: javax.swing.Icon
Java API: java.awt.AlphaComposite

4 Responses to “Alpha Icons”

  1. Hi Darryl, it looks like both links point to instead ;-)

  2. Moiz Bhukhiya said

    Can these classes be used for commercial purpose? Thanks!

    • Like all code published on the blog, these classes are free to use, at your own risk . A link to the blog page in the doc comments or elsewhere would be nice, but is by no means mandatory.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: