Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to prevent a JInternalFrame from closing

843805Aug 3 2006 — edited Aug 4 2006
I'm using a JInternalFrame with a InternalFrameAdapter to display a YES/NO exit confirmation before closing the frame.
myInternalFrame.setDefaultCloseOperation(JInternalFrame.DO_NOTHING_ON_CLOSE);
    myInternalFrame.addInternalFrameListener(new MyInternalFrameAdapter(
        ....
        public void internalFrameClosing(InternalFrameEvent e) {
            int result = JOptionPane.showConfirmDialog(myInternalFrame,
                "Are you sure you want to close the window?", 
                "Close", 
                JOptionPane.YES_NO_OPTION );

	    if (result == JOptionPane.YES_OPTION) {
	       myInternalFrame.dispose();
	    }
	    .... 
	}

    ));
This works fine if I close the frame by clicking the [x] button in the top right hand corner. If I try to close the frame programmatically, it displays the confirmation, but still closes the window even if I click NO.
    
   ....
   myInternalFrame.setClosed(true);
   ....
What am I doing wrong? How do I prevent the frame from closing if I click NO?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 1 2006
Added on Aug 3 2006
7 comments
487 views