Take the 2-minute tour ×

According to another discussion here, I try to open a modal view like so:

public void widgetSelected(SelectionEvent e) {

    final Shell dialogShell = new Shell(ApplicationRunner.getApp()
            .getShell().getDisplay(), SWT.PRIMARY_MODAL | SWT.SHEET);

    dialogShell.setLayout(new FillLayout());

    Button closeButton = new Button(dialogShell, SWT.PUSH);
    closeButton.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {

        public void widgetDefaultSelected(SelectionEvent arg0) {
            // TODO Auto-generated method stub

    dialogShell.addDisposeListener(new DisposeListener() {

        public void widgetDisposed(DisposeEvent e) {
            System.out.println("Modal dialog closed");

It opens the desired window, but it's not modal. I can access the main shell and open another instance of the same modal dialog. Can anybody point me in the right direction?

Thanx, Marcus

share|improve this question

1 Answer 1

up vote 3 down vote accepted

I would highly recommend creating your own JFace Dialog by extending org.eclipse.jface.dialogs.Dialog rather than creating your own shell with buttons. Here is a really good tutorial on this.

Within the contructor you can call setShellStyle(SWT.CLOSE | SWT.TITLE | SWT.BORDER | SWT.OK | SWT.APPLICATION_MODAL); which will make this dialog completely modal, if you call the constructor with your main shell as the parameter. Like this:

public CheckboxDialog(Shell parentShell) {

where parentShell is the main shell of your GUI.

share|improve this answer
thanx to you, again 8) seems like, there are not many programmers around, dealing with stw/jface (anymore). Did I miss a new and flashy possibility to do desktop applications? –  Marcus Toepper Aug 25 '12 at 8:57
@MarcusToepper Itoo was surprised, that there aren't many SWT developers around. Seems they are all dealing with Swing/AWT. I've worked with both and I really prefer SWT... –  Baz Aug 25 '12 at 9:06
Considering the age of both, one would think, there might be any new APIs around anyway, but these days, everything seems to evolve around web solutions only. Like JavaFX for applications or something like that. –  Marcus Toepper Aug 26 '12 at 7:31

Your Answer


