The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > javax.swing  [141 examples] > JFrame, JWindow, JDialog  [6 examples]

e735. Disabling the Close Button on a JFrame

By default, when the close button on a frame is clicked, the frame hides itself. This example shows how to disable the close button:
    // Create a frame
    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);

 Related Examples
e733. Creating a JFrame
e734. Exiting an Application When a JFrame Is Closed
e736. Creating a Borderless Window
e737. Showing a Dialog Box
e738. Getting the JFrame of a Component

See also: Actions    JButton    JCheckBox    JComboBox    JDesktop and JInternalFrame    JLabel    JList    JProgressBar    JRadioButton    JScrollPane    JSlider    JSpinner    JSplitPane    JTabbedPane    JToolBar    Keystrokes and Input Maps    Layout    Look and Feel    Menus    Progress Monitor    The Screen    Tool Tips    UI Default Values   


© 2002 Addison-Wesley.