How to create a Titleless and Borderless JFrame in Java?

Java 8Object Oriented ProgrammingProgramming

To create a Titleless and Borderless JFrame, use the setUndecorated() method and set it to TRUE −

JFrame frame = new JFrame("Register!");
frame.setUndecorated(true);

The following is an example to create a titleless and borderless JFrame −

Example

package my;
import java.awt.GridLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
public class SwingDemo {
   public static void main(String[] args) throws Exception {
      JFrame frame = new JFrame("Register!");
      JLabel label1, label2, label3;
      frame.setLayout(new GridLayout(2, 2));
      label1 = new JLabel("Id", SwingConstants.CENTER);
      label2 = new JLabel("Age", SwingConstants.CENTER);
      label3 = new JLabel("Password", SwingConstants.CENTER);
      JTextField emailId = new JTextField(20);
      JTextField age = new JTextField(20);
      JPasswordField passwd = new JPasswordField();
      passwd.setEchoChar('*');
      frame.add(label1);
      frame.add(label2);
      frame.add(label3);
      frame.add(emailId);
      frame.add(age);
      frame.add(passwd);
      frame.setUndecorated(true);
      frame.setSize(550, 400);
      frame.setVisible(true);
   }
}

Output

raja
Published on 06-Jun-2019 08:43:10
Advertisements