• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to make a JComponet transparent?

 
Tseng-Kuei Li
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Although I have reviewed the Java2 SDK document and I found that in the class Color we can get transparency by getTransparency, I do not know how to use such a method to make a JComponent transparent. Or there may be other methods which can be used.
 
Joe Gilvary
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
The getTransparency call only tells you what the
value for the transparency (the alpha value) is
for the color.
You need to set the alpha value to 0.0 when you
construct the Color that is to be transparent.
Check the documentation for the java.awt.Color
class. There is a constructor which takes values
for red, green, blue, and alpha. That's the one
you need.
HTH,
Joe
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just make the transparent color as Joe said above and set it as the background of the component... here's a demonstration...



-Nate
 
Tseng-Kuei Li
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have tried and got something transparent. Thanks very much.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!