Hi all,
I am back after a long time. This time I want to tell you all how I set a window as translucent in java. It was a very cumbersome thing to do before recently. From JDK 6 update 10, java has this facility to set the window as translucent and its very easy.
Recently I did this in one of my projects and wanted to share it with you all.
As of the Java Platform, Standard Edition 6 (Java SE 6) Update 10 release, we can add translucent and shaped windows to our Swing applications.
The translucent and shaped window API was first added to the Java SE 6 Update 10 release as a private API. This functionality was moved to the public AWT package in the JDK 7 release.
Here is an example :
import java.awt.*;
import javax.swing.*;
import static java.awt.GraphicsDevice.WindowTranslucency.*;
public class MyWindow extends JFrame {
public MyWindow() {
super("MyWindow");
setLayout(new GridBagLayout());
setSize(300,200);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
add(new JButton("Just a Button"));
}
public static void main(String[] args) {
// Determine if the GraphicsDevice supports translucency.
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd = ge.getDefaultScreenDevice();
//If translucent windows aren't supported, exit.
if (!gd.isWindowTranslucencySupported(TRANSLUCENT)) {
System.err.println( "Translucency is not supported");
System.exit(0);
}
SwingUtilities.invokeLater(new Runnable() {
public void run() {
MyWindow tw = new MyWindow();
// Set the window to 55% opaque (45% translucent).
tw.setOpacity(0.55f);
// Display the window.
tw.setVisible(true);
}
});
}
}
To learn more please check this link.
Here is how you can select which methods to use according to your JDK version.
–
Regards,
Manohar Bhattarai (मनोहर भट्टराई)
http://about.me/manoharbhattarai
http://www.facebook.com/pages/Manohar-Bhattarai/130973796914160
Blogs:
http://manoharbhattarai.wordpress.com/
http://manoharbhattarai.posterous.com/
http://manoharbhattarai.blogspot.com/
Microblogs:
Twitter :- http://twitter.com/mhrbhattarai
Identi.ca :- http://identi.ca/manoharbhattarai
Tags: how to, how to create translucent window, how to create translucent window in java, howto, java, java 7, java 7 docs, java 7 features, java features, java swing, java7, jdk7, jdk7 java docs, jdk7 javadocs, Manohar, Manohar Bhattarai, Swing, translucency, translucency in java, translucency in java swing, translucent, translucent window in java, which java
September 14, 2011 at 9:39 am |
That is the proper blog for anybody who needs to find out about this topic. You realize so much its virtually exhausting to argue with you (not that I really would need…HaHa). You undoubtedly put a brand new spin on a subject thats been written about for years. Great stuff, just nice!
September 20, 2011 at 12:58 pm |
I love blogs and i also can tell you additionally like blogs.
October 2, 2011 at 8:51 am |
[...]in this page you can find our links to articles , we noticed these are worth visiting[...]…
October 3, 2011 at 3:53 am |
add your code…
[...]How to Create Translucent and Shaped Windows in java. « Manohar Bhattarai[...]…