File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes How to make a JFrame transparent with solid border Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to make a JFrame transparent with solid border" Watch "How to make a JFrame transparent with solid border" New topic
Author

How to make a JFrame transparent with solid border

Nam Ha Minh
Ranch Hand

Joined: Oct 31, 2011
Posts: 498

Hi guys,

I am wondering how to make the content pane of a JFrame transparent, but not its border. The border is still opaque and solid.

Does anyone have ideas?


PM Me If You Want to get Urgent Help on Java Programming
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38412
    
  23
What happens if you try getcontentPane().setOpaque(false);?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38412
    
  23
Earlier, I wrote:What happens if you try getcontentPane().setOpaque(false);?
Container hans’t got a setOpaque method, so you’d get a compiler error.
There is such a method in JComponent. What happens if you set the content pane to a JComponent (eg JPanel) and call setOpaque(false) on that panel.
There appears to be a setOpacity(float) method in the AWT counterparts, too.
Kocha Sapam
Ranch Hand

Joined: Aug 04, 2012
Posts: 35
As said above, just create a JPanel instance and set it as the content pane, then call setOpaque(false) on that instance something like :
JPanel content = new JPanel();
yourjframe.setContentPane(content);
content.setOpaque(false);

but let me ask something, whats the point of making the content pane transparent without the jframe being transparent ?

Edit : if you really want to make the whole frame (including jframes, jpanels, etc.) see through, i can tell how to, just decide and reply. Even if you want solid borders, we can cook it together (trust me).
Well that was my $0.02 ;)
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38412
    
  23
Kocha Sapam wrote: . . . Well that was my $0.02 ;)
We usually charge a lot more than that for private work

And welcome to the Ranch
Kocha Sapam
Ranch Hand

Joined: Aug 04, 2012
Posts: 35
Well, that was hillarius, thanks ;)
Nam Ha Minh
Ranch Hand

Joined: Oct 31, 2011
Posts: 498

Kocha Sapam wrote:As said above, just create a JPanel instance and set it as the content pane, then call setOpaque(false) on that instance something like :
JPanel content = new JPanel();
yourjframe.setContentPane(content);
content.setOpaque(false);


I just tried that, the whole frame is still opaque.


Kocha Sapam wrote:but let me ask something, whats the point of making the content pane transparent without the jframe being transparent ?

Well, the point is I want to create a resizable transparent window with only the border painted. This is a part of a screen recorder application.

Kocha Sapam wrote:
Edit : if you really want to make the whole frame (including jframes, jpanels, etc.) see through, i can tell how to, just decide and reply. Even if you want solid borders, we can cook it together (trust me).
Well that was my $0.02 ;)


Thanks, I already got it cooked
Kocha Sapam
Ranch Hand

Joined: Aug 04, 2012
Posts: 35
^You mean your problem is solved ? If not, please specify your jdk version (like JDK6u14 above or JDK7 above, the solution differs on the version). Also, this solution *may not* work on linux.

Regards - Kocha
Nam Ha Minh
Ranch Hand

Joined: Oct 31, 2011
Posts: 498

Kocha Sapam wrote:^You mean your problem is solved ? If not, please specify your jdk version (like JDK6u14 above or JDK7 above, the solution differs on the version). Also, this solution *may not* work on linux.

Regards - Kocha


Yes, I am using AWTUtilities to set the frame transparent, then I draw solid border on the glass pane. It works from Java 1.6 and above.
Kocha Sapam
Ranch Hand

Joined: Aug 04, 2012
Posts: 35
That's cool, exactly what I expected. But be careful, there is no com.sun.awt.AWTUtilities class as of JDK7, they have different classes in the java.awt package (i forgot the classnames, hope you already know them :P)

Ahhh! It's in the Window class, you can call setOpaque(false) on any of its decendents like jframe etc. So you'd simply call yourJFrame.setOpacity(0.0f) instead of AWTUtilities.setWindowOpaque(yourJFrame, false)
 
wood burning stoves
 
subject: How to make a JFrame transparent with solid border