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?