When a user closes any of the application windows using the Window Close Button(red X) button. It causes Widget is Disposed issues with my application. When they close the window using the close application I provided. Everything works correctly.
@Override
protected void createButtonsForButtonBar(Composite parent) {
createButton(parent, IDialogConstants.OK_ID, "Close Aplot", true);
}
@Override
protected void okPressed() {
getShell().setVisible(false);
}
Listen for SWT.Close on the Shell.
This should help:
public static void main(String[] args)
{
Display display = new Display();
final Shell shell = new Shell(display);
shell.addListener(SWT.Close, new Listener()
{
public void handleEvent(Event event)
{
int style = SWT.APPLICATION_MODAL | SWT.YES | SWT.NO;
MessageBox messageBox = new MessageBox(shell, style);
messageBox.setText("Information");
messageBox.setMessage("Close the shell?");
event.doit = messageBox.open() == SWT.YES;
}
});
shell.pack();
shell.open();
while (!shell.isDisposed())
{
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
It will prompt the user to verify the decision.
In a jface dialog, always it will invoke close() method irrespective of where OK is pressed or CANCEL is pressed or close(red x button) is clicked.
Override close method and check return code ( use getReturnCode() method).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With