Displays a shaped JFrame - Java Swing

Java examples for Swing:JFrame

Description

Displays a shaped JFrame

Demo Code

import java.awt.BorderLayout;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Path2D;
import java.awt.geom.Rectangle2D;

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() {
    setUndecorated(true);//from  ww  w.  j  av a  2  s  .  co m

    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setSize(200, 200);

    Ellipse2D.Double ellipse = new Ellipse2D.Double(0, 0, 200, 100);
    Rectangle2D.Double rect = new Rectangle2D.Double(0, 120, 240, 200);

    Path2D path = new Path2D.Double();
    path.append(rect, true);
    path.append(ellipse, true);
    this.setShape(path);

    add(closeButton, BorderLayout.SOUTH);
    closeButton.addActionListener(e -> System.exit(0));
  }

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

Related Tutorials