本文介绍了显示来自AWT/Swing的SWT模态对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Albireo,很容易看到如何显示来自SWT的Swing对话框:

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);
        }
    }
}

我想显示一个来自AWT线程的SWT对话框,即

// call from AWT thread
void showSWTMessageDialog(String msg) {
    ???
}
解决方案

我不确定,如果我对这个问题理解得很好,但是当您使用Albireo/SWT_AWT桥编写程序时,可以正常使用SWT,并且在需要时,您可以使用Swing进行一些工作(如有关Eclipse Wiki的示例所示).您在某些全局属性中具有您的父级(最可能是Shell实例),您可以随时随地创建SWT对话框.

编辑

要阻止AWT线程,您可以调用方法并在Runnable实例内部显示SWT对话框窗口.

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) {
    ???
}
解决方案

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..

这篇关于显示来自AWT/Swing的SWT模态对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 03:51