In a GUI programming at some point the transparent windows are very much in need. The transparent frames are mostly used to show some less important content to users. It is basically a JFrame with faded color. It can also used in creating some widget in a very large application. Here is a code snippet.
import javax.swing.JFrame;
import java.awt.Color;
public class TransparentDemo extends JFrame{
public TransparentDemo(){
setSize(200, 200);
/***
* To make a JFrame transparent this method needs to be set to true
* if this method is not set to true this will throw an exception
* java.awt.IllegalComponentStateException
*/
setUndecorated(true);
/***
* The Transparency of the frame is mainly done with the help of
* class Color of the package java.awt
* class Color of the package java.awt
* there are 3 arguments of the construction first 3 args are of
* color red, green, and blue and the
* color red, green, and blue and the
* the last 4th argument is called opacity which is an integeral
* number raging from 0 to 100 which
* number raging from 0 to 100 which
* will improve the opacity from 100 to 0 means 0 will be no
* background and 100 will be pure
* background and 100 will be pure
* background with color.
*/
setBackground(new Color(10,200,255,90));
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String args[]){
new TransparentDemo().setVisible(true);
}
}
Type the above code in notepad or any editor and run it.