This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Partially transparent backgrounds ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Partially transparent backgrounds ?" Watch "Partially transparent backgrounds ?" New topic

Partially transparent backgrounds ?

Julie de Wet

Joined: Apr 04, 2004
Posts: 17

I have a gui with a picture as background, and transparent labels. I want to set the background of the labels so that they are only partially transparent, so that my background is less obtrusive where I have text.

As far as I can see a label can either be opaque or transparent and not some inbetween value.

I tried using a gif which was partially transparent as background for the label and setting opaque to false, but that didn't work

Does anyone else know how, or have any suggestions

David Weitzman
Ranch Hand

Joined: Jul 27, 2001
Posts: 1365
You might want to try

label.setBackground(new Color(redComponent, greenComponent, blueComponent, 30));

Where 30 is just an arbitrary alpha value from 0-255 setting the transparency (0 is invisible, 255 is opaque). However when I tried it (two partially transparent backgrounds for JLabels in a JLayeredPane) the background was actually changing color after Maybe it'll work for you?

The first alternative which comes into my mind is this:

I agree. Here's the link:
subject: Partially transparent backgrounds ?
It's not a secret anymore!