To change the behavior of the X button, you may set the default close operation to DO_NOTHING_ON_CLOSE
, and add an InternalFrameListener
which will take care of asking for closing confirmation, and closing the frame if needed :
internalFrame.setDefaultCloseOperation(JInternalFrame.DO_NOTHING_ON_CLOSE);
internalFrame.addInternalFrameListener(new InternalFrameListener() {
@Override
public void internalFrameOpened(final InternalFrameEvent e) {
}
@Override
public void internalFrameClosing(final InternalFrameEvent e) {
// Do your confirmation stuff !!
// Dispose the internal frame if needed !!
}
@Override
public void internalFrameClosed(final InternalFrameEvent e) {
}
@Override
public void internalFrameIconified(final InternalFrameEvent e) {
}
@Override
public void internalFrameDeiconified(final InternalFrameEvent e) {
}
@Override
public void internalFrameActivated(final InternalFrameEvent e) {
// TODO Auto-generated method stub
}
@Override
public void internalFrameDeactivated(final InternalFrameEvent e) {
// TODO Auto-generated method stub
}
});
DO_NOTHING_ON_CLOSE
Do nothing. This requires the program to handle
the operation in the windowClosing method of a registered
InternalFrameListener object.
(note that in the above documentation extract, I suspect that windowClosing
is a typo, they probably meant internalFrameClosing
) .
See : JInternalFrame.setDefaultCloseOperation