Showing SWT modal dialog from AWT/Swing

爷,独闯天下 提交于 2019-12-11 10:51:44

问题


Using Albireo, it's easy to see how to show a Swing dialog from SWT:

private AwtEnvironment awtEnv = AwtEnvironment.getInstance(Display.getCurrent);

...
// call from SWT thread
void showSwingMessageDialog(String msg) {
    awtEnv.invokeAndBlockSwt(new Runnable() {
        public void run() {
            Frame parentFrame = awtEnv.createDialogParentFrame();
            JOptionPane.showMessageDialog(parentFrame, msg);
        }
    }
}

I want to show an SWT dialog from AWT thread, i.e.

// call from AWT thread
void showSWTMessageDialog(String msg) {
    ???
}

回答1:


I'm not sure, if I understand this question well, but when you are writing program with Albireo/SWT_AWT bridge, you use SWT normally and when you need, you can use Swing for some work (as this example on eclipse wiki shows).. So if you have your parent (most probably Shell instance) in some global attribute, you can just create SWT dialog whenever and wherever you need..

EDIT

For blocking the AWT thread, you could call invokeAndWait() method of SwingUtilities and inside the Runnable instance show the SWT dialog window..



来源:https://stackoverflow.com/questions/6763254/showing-swt-modal-dialog-from-awt-swing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!