Java Swing How to - Create JFrame with no border and title bar








Question

We would like to know how to create JFrame with no border and title bar.

Answer

import java.awt.event.ActionEvent;
//w ww  . ja va2 s  .co  m
import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class Main {

  public static void main(String[] args) {
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setUndecorated(true);
    JPanel panel = new JPanel();
    panel.add(new JLabel("Stackoverflow!"));
    panel.add(new JButton(new AbstractAction("Close") {
      @Override
      public void actionPerformed(ActionEvent e) {
        System.exit(0);
      }
    }));
    f.add(panel);
    f.pack();
    f.setVisible(true);
  }
}