Using a Uniform Translucent JFrame - Java Swing

Java examples for Swing:JFrame

Description

Using a Uniform Translucent JFrame

Demo Code

import java.awt.BorderLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;

public class Main extends JFrame {
  private JButton closeButton = new JButton("Close");

  public Main(String title) {
    super(title);
    initFrame();// w  w w  .ja  v  a 2 s. c o m
  }

  public void initFrame() {
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setUndecorated(true);
    setOpacity(0.40f);
    setSize(200, 200);
    setLocationRelativeTo(null);
    add(closeButton, BorderLayout.SOUTH);
    closeButton.addActionListener(e -> System.exit(0));
  }

  public static void main(String[] args) {
      Main frame = new Main("Translucent Frame");
      frame.setVisible(true);
  }
}

Related Tutorials