• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Transparent Frame in Frame

 
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?
 
Marshal
Posts: 70646
288
  • 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
Marshal
Posts: 70646
288
  • 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.
 
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
 
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.
 
Get me the mayor's office! I need to tell her about this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic