How to create JFrame with no border and title bar in Java?

Java 8Object Oriented ProgrammingProgramming

To create a JFrame with no border and title bar, use setUndecorated() −

JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setPreferredSize(new Dimension(400, 300));
frame.setUndecorated(true);

The following is an example to create JFrame with no border and title bar −

Example

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class SwingDemo {
   public static void main(String[] args) {
      JFrame frame = new JFrame();
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setPreferredSize(new Dimension(400, 300)); frame.setUndecorated(true);
      JPanel panel = new JPanel();
      panel.add(new JLabel("Demo!"));
      panel.add(new JButton(new AbstractAction("Close") {
         @Override
         public void actionPerformed(ActionEvent e) {
            System.exit(0);
         }
      }));
      frame.add(panel);
      frame.pack();
      frame.setVisible(true);
   }
}

Output

raja
Updated on 30-Jul-2019 22:30:26

Advertisements