Making a component half way transparent(not fully opaque or nuopaque)

Is it possible to make a component (frame, panel etc) half way transparent, I know that its possible to make it fully transparent but i would like to know of a way to go half way, thanks.
[194 byte] By [P.F.a] at [2007-11-27 8:21:21]
# 1

I saw something recently about making a JFrame transparent in another question. You need to use a third party package. Sorry, I don't remember the posting. If you try searching the forum you might find it again. You can use my id as one of the keywords.

Otherwise for JComponents you need to do three things:

a) make the component non-opaque

b) set the background color of the component using a Color object that has an "alpha" value specified.

c) however you can't just set the background since it won't automatically be painted, so you need to override the paintComponent() method of the component to paint the background yourself. Something like:

g.setColor(getBackground());

g.fillRect(0, 0, getWidth(), getHeight());

super.paintComponent(g);

Or instead of using a background with an alpha value I think you can use something like this to paint the background:

Graphics2D g2 = (Graphics2D)g;

AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha);

g2.setComposite(ac);

g2.setPaint(getBackground());

g2.fillRect(0, 0, getWidth(), getHeight());

Don't know which approach is better.

camickra at 2007-7-12 20:09:52 > top of Java-index,Desktop,Core GUI APIs...
# 2
yeah i assume that alpha idea will work, thank you
P.F.a at 2007-7-12 20:09:52 > top of Java-index,Desktop,Core GUI APIs...