Making a Java Swing JFrame Transparent

programming

This is how you can create a transparent JFrame in JAVA.

public class transparentJFrame {
 public static void main(String[] args) {
  new transparentJFrame(Date, Head, Detal);
 }
 public transparentJFrame(String Date, String Head, String Detal) {

  JFrame frame = new JFrame();
  frame.setUndecorated(true);
  frame.setBackground(new Color(Color.black.getRed(), Color.black.getGreen(), Color.black.getBlue(), 1));
  //Change value of '1' above to have diff transparency
  ((JComponent) frame.getContentPane()).setBorder(
   BorderFactory.createMatteBorder(3, 2, 2, 2, Color.black));
  frame.setBounds(100, 50, 500, 400);
  frame.getContentPane().setLayout(null);

  final JLabel lblX = new JLabel("X");
  lblX.setBounds(frame.getWidth() - 15, 5, 15, 15);
  lblX.setForeground(new Color(255, 255, 255));
  lblX.setToolTipText("Closern");
  lblX.addMouseListener(new MouseAdapter() {
   @Override
   public void mouseClicked(MouseEvent arg0) {
    frame.dispose();
   }
   @Override
   public void mouseEntered(MouseEvent e) {
    lblX.setForeground(new Color(255, 0, 0));
   }
   public void mouseExited(MouseEvent e) {
    lblX.setForeground(new Color(255, 255, 255));
   }
  });
  lblX.setFocusable(false);
  frame.getContentPane().add(lblX);
  frame.setVisible(true);
 }
}
Bikash Panda
Catch Me On