一般在swt的窗口中打开swt的dialog只要
SampleDialog dialog = new SampleDialog(shell);
dialog.open();如何在Swing的JFrame中打开一个SWT dialog?

解决方案 »

  1.   

    Display ds = Display.getDefault();
    Shell sl = ds.getShell();
    SampleDialog dialog = new SampleDialog(shell); 
    dialog.open(); 
      

  2.   

    好像不行,ds没有getShell()的方法,有一个getActiveShell(),我用了getActiveShell()之后运行程序报错
    org.eclipse.swt.SWTException: Invalid thread access
      

  3.   

    没Eclipse,忘记了,不好意思。直接 new Shell() 不就可以了吗?
      

  4.   

    如果在JFrame那个类里Shell sl = new Shell();就会抛出
    org.eclipse.swt.SWTException: Invalid thread access
      

  5.   

    机器上没有SWT的环境,另起一个线程试试。直接在事件派发线程中当然不行了
      

  6.   


    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;import javax.swing.JButton;
    import javax.swing.JFrame;import org.eclipse.jface.dialogs.Dialog;
    import org.eclipse.swt.widgets.Composite;
    import org.eclipse.swt.widgets.Control;
    import org.eclipse.swt.widgets.Display;
    import org.eclipse.swt.widgets.Shell;
    public class Test extends JFrame{ public Test(){
    JButton b = new javax.swing.JButton();
    b.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e) {
    Display d = Display.getDefault();
    Shell s = d.getActiveShell();
    new Dialog(s){
    @Override
    protected Control createDialogArea(Composite parent) {
    return super.createDialogArea(parent);
    }

    }.open();
    }
    });

    getContentPane().add(b);
    }

    public static void main(String[] args){
    Test t = new Test();
    t.show();
    }
    }
    家里没有SWT的环境,原以为在事件派发线程中可能会有问题,早晨看了一下事件没有问题