wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes Transparent Frame in Frame Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Transparent Frame in Frame" Watch "Transparent Frame in Frame" New topic
Author

Transparent Frame in Frame

Tim Berett
Ranch Hand

Joined: Jun 14, 2002
Posts: 35
Can I have a transparent frame in a JFrame/Frame and where I can control the transparency level?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38350
    
  23
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

Joined: Oct 13, 2005
Posts: 38350
    
  23
I don't know whether this is relevant, but there is information about colour transparency in the Java tutorial here.
Ken Blair
Ranch Hand

Joined: Jul 15, 2003
Posts: 1078
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

Joined: Jun 14, 2002
Posts: 35
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

Joined: Jul 03, 2006
Posts: 59
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Transparent Frame in Frame