Disabling the Close Button on a JFrame - Java Swing

Java examples for Swing:JFrame

Description

Disabling the Close Button on a JFrame

Demo Code

import javax.swing.JFrame;

public class Main {
  public static void main(String[] args) throws Exception {
    JFrame frame = new JFrame();

    // Get default close operation
    int op = frame.getDefaultCloseOperation(); // HIDE_ON_CLOSE

    // Set to ignore the button
    frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
  }/*from w  w  w. j  a  va2s .  co m*/
}

Related Tutorials