This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
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
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Reply 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: 346

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?


Job Offer: Online working Java technical writing
Campbell Ritchie
Sheriff

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

Joined: Oct 13, 2005
Posts: 32704
    
    4
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: 32704
    
    4
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: 346

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: 346

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)
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: How to make a JFrame transparent with solid border
 
Similar Threads
Div positioning problem
Transparent JcomboBox
Java Timer & Clock
win style resize rectangle when using metal plaf
How to make a JFrame transparent