How to close Java SWT window with a button?

As a newbie to Java and years of experience with iOS and .NET, I found this to be rather confusing. I would like it to be very simple - I want a dialog (called from the main window) with the OK and Cancel buttons. When you click OK, he does something and then rejects the dialog. When you click Cancel, it will simply reject the dialog.

However, doing this using the SWT wrapper of a Dialog class is not obvious. How do you get a button to reject a dialog and return execution to the main window?

+4
source share
2 answers

Use Shell.close(), not dispose()so shlCheckOut.close().

Shell.close SWT.Close, dispose.

+4

, , .dispose() . , CheckOutDialog, shlCheckOut. createContents() :

...

Button btnCancel = new Button(shlCheckOut, SWT.NONE);
btnCancel.addSelectionListener(new SelectionAdapter() {
    @Override
        public void widgetSelected(SelectionEvent e) {
            shlCheckOut.dispose();
        }
    }
}
+3

All Articles