How to Support JFrame transparency on Linux


How to Support JFrame transparency on Linux



I'm making a java swing application which is executed on linux machine and shown in users' computer by X11 forwarding.

I want to apply rounded corners on JFrame, so I changed its background to new Color(0,0,0,0).
The frame is now hidden on my computer(windows 10). But the linux(centOS7) doesn't seem not to support Window Frame transparency.

It returns error below.


Exception in thread "AWT-EventQueue-0"
java.lang.UnsupportedOperationException: PERPIXEL_TRANSLUCENT translucency is not supported
at java.awt.Window.setBackground(Window.java:3844)
at java.awt.Frame.setBackground(Frame.java:988)



Without changing its background works fine on both but the default background is also shown.
Is there any way to make rounded corners??
Thank you.




1 Answer
1



Not every platfrom supports transparency.



Take a look at https://docs.oracle.com/javase/tutorial/uiswing/misc/trans_shaped_windows.html



chapter
Determining a Platform's Capabilities


import static java.awt.GraphicsDevice.WindowTranslucency.*;

// Determine what the default GraphicsDevice can support.
GraphicsEnvironment ge =
GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd = ge.getDefaultScreenDevice();

boolean isUniformTranslucencySupported =
gd.isWindowTranslucencySupported(TRANSLUCENT);
boolean isPerPixelTranslucencySupported =
gd.isWindowTranslucencySupported(PERPIXEL_TRANSLUCENT);
boolean isShapedWindowSupported =
gd.isWindowTranslucencySupported(PERPIXEL_TRANSPARENT);



To be tested, but I don't thing that X11 forwarding allows transparency !



EDIT
Just made a test, through ssh -X, java version 1.8.0_162-b12
and it works.
What is your java version ?



enter image description here





Via X11, returns false, false, and true. It means I cannot make the border conered, ehh? Please... I have to make it. I both tried java 6 and 8 but same.
– Bana
Jul 3 at 11:00






You need at least Java 7. Try this example : docs.oracle.com/javase/tutorial/uiswing/examples/misc/…. BTW, I use Oracle's JVM, not OpenJDK's one
– olikaf
Jul 3 at 11:53







By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

api-platform.com Unable to generate an IRI for the item of type

How to set up datasource with Spring for HikariCP?

Display dokan vendor name on Woocommerce single product pages