| 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
|
|
|
What happens if you try getcontentPane().setOpaque(false);?
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32704
|
|
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
|
|
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)
|
 |
 |
|
|
subject: How to make a JFrame transparent with solid border
|
|
|