SWT模态对话框不是模态的

Mar*_*per 3 java swt dialog modal-dialog

根据这里的另一个讨论,我尝试打开一个模态视图,如下所示:

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.setText("Close");
    closeButton.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            dialogShell.dispose();
        }

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

        }
    });
    dialogShell.setDefaultButton(closeButton);
    dialogShell.addDisposeListener(new DisposeListener() {

        public void widgetDisposed(DisposeEvent e) {
            System.out.println("Modal dialog closed");
        }
    });
    dialogShell.pack();
    dialogShell.open();
}
Run Code Online (Sandbox Code Playgroud)

它会打开所需的窗口,但它不是模态的.我可以访问主shell并打开同一模态对话框的另一个实例.任何人都能指出我正确的方向吗?

Thanx,马库斯

Baz*_*Baz 7

我强烈建议您通过扩展org.eclipse.jface.dialogs.Dialog而不是使用按钮创建自己的shell来创建自己的JFace对话框. 是一个非常好的教程.

在构造setShellStyle(SWT.CLOSE | SWT.TITLE | SWT.BORDER | SWT.OK | SWT.APPLICATION_MODAL);函数中,如果使用主shell作为参数调用构造函数,则可以调用哪个将使此对话框完全模态化.像这样:

public CheckboxDialog(Shell parentShell) {
    super(parentShell);
    setShellStyle(SWT.CLOSE | SWT.TITLE | SWT.BORDER | SWT.OK | SWT.APPLICATION_MODAL);
    setBlockOnOpen(true);
}
Run Code Online (Sandbox Code Playgroud)

parentShellGUI的主要外壳在哪里.