• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Transparent Frame in Frame

 
Tim Berett
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can I have a transparent frame in a JFrame/Frame and where I can control the transparency level?
 
Campbell Ritchie
Sheriff
Pie
Posts: 48940
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look through the JFrame API description and start from the getContentPane() method. I don't think you are supposed to have things transparent, but I think that is your starting point.

If you want transparent colours, try the alpha attribute in java.awt.Color.

There are ways of combining two images of different transparency: see for example, Horstmann C, Cornell G, Core Java 2: vol II advanced features, Upper Saddle River NJ: Prentice-Hall (Sun Microsystems Press) (2004), pages 500-508, or do a search on Porter Duff OR Foley van Dam Feiner.
 
Campbell Ritchie
Sheriff
Pie
Posts: 48940
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know whether this is relevant, but there is information about colour transparency in the Java tutorial here.
 
Ken Blair
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not without essentially coding it yourself. Since transparent frames aren't available in most operating systems there isn't any support for it in AWT or Swing. It's possible to work around it using a Robot, but I've never seen that actually work well enough to be useful. What you may be talking about is drawing a lightweight semi-transparent frame on top of a heavyweight opaque frame. That is possible, but to my knowledge there is no support in the API for it. Unless there's something I don't know about and, there may very well be especially in 1.6, you'd have to write the frame yourself. It actually isn't that tough, but it's a decent amount of work.
 
Tim Berett
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ken,

Yes, I wanted a semi transparent frame over a opaque frame. Has anyone done it before? Thank you.

Tim Berett
 
Nick Meverden
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim, along the lines of what Ken said there is a "hack" in the book called Swing Hacks that shows how to use Robot to take a screenshot and use paintComponent() to draw the screenshot into the JFrame to give it the effect of trans using Graphics2D. If the video card has fast enough 2D acceleration visually the user won't notice.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic