• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Transparent Frame in Frame

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can I have a transparent frame in a JFrame/Frame and where I can control the transparency level?
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic