MessageBox msg = new MessageBox(shell, SWT.ICON_INFORMATION | SWT.OK);我这样新建的MessageBox必须点ok才能继续操作shell窗口中的别的内容,我想实现在shell中一点按钮就出一个MessageBox,可以同时出现多个MessageBox,能实现吗?还是必须得改用Dialog才能实现?

解决方案 »

  1.   

    MessageBox 是模式对话框,会阻塞界面线程。
      

  2.   

    自己写非模式对话框,例如:
    public class TestDialog extends TitleAreaDialog {

    public TestDialog(Shell parentShell) {
    super(parentShell);
    setShellStyle(SWT.MODELESS | SWT.DIALOG_TRIM | getDefaultOrientation());
    }

    @Override
    protected Control createDialogArea(Composite parent) {

    final Composite composite = (Composite) super.createDialogArea(parent);

    Button button = new Button(composite, SWT.PUSH);
    button.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false,
    false));
    button.setText("OK");

    final Shell shell = this.getShell();

    shell.addFocusListener(new FocusListener(){ public void focusGained(FocusEvent e) {
    shell.getDisplay().asyncExec(new Runnable(){
    public void run() {
    getParentShell().setFocus();
    }
    });
    } public void focusLost(FocusEvent e) {
    // TODO Auto-generated method stub

    }

    });

    return composite;
    }

    }
    然后,就可以了。