How-To: Create a Transparent JFrame in Java Swing

Here is a sample tutorial, can be a swing hack to optimize your JFrame to give it a better look through transparency.

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class TransparentJFrame extends JFrame
JButton b1;
public TransparentJFrame()
setTitle("Transparent JFrame Demo");
setLayout(new GridBagLayout());
//For Java 1.7 or above
//For lower java versions
b1=new JButton("I am a button!");
public static void main(String args[])
new TransparentJFrame();
GridBagLayout: To make the JButton come to center. You can use your own layout depending upon your wish.

Posted by at on

Tags: Swing Components, Swing Hacks,