已有源码是用AWT写的,现在要做扩充,GUI程序,能够同时让AWT和SWT做的界面运行吗.
比如主界面是基于AWT写的,点击一个按钮,出来一个基于SWT的对话框,可以吗?请教达人!

解决方案 »

  1.   

    如果能把主界面的JDialog改成shell的话可以利用Frame frame = SWT_AWT.new_Frame(composite);生成一个frame ,把原来的东西全部迁移到这个frame 上的话就可以做
    final Frame frame = SWT_AWT.new_Frame(composite); final JButton button_1 = new JButton();
    button_1.addActionListener(new ActionListener() {
    public void actionPerformed(final ActionEvent arg0) {
    Display.getDefault().asyncExec(new Runnable(){ @Override
    public void run() {
    Shell shell = new Shell(Display.getDefault(), SWT.NONE);
    shell.setText("SWT Application");
    shell.setSize(500, 375);
    shell.open();
    shell.layout();
    }});

    }
    });
    这个是可以打开一个新的shell,但是如果不能改我是了一下
    final JButton button = new JButton();
    button.addActionListener(new ActionListener() {
    public void actionPerformed(final ActionEvent e) {
    final Display display = Display.getDefault();
    Display.getDefault().asyncExec(new Runnable(){ @Override
    public void run() {
    Shell shell = new Shell(display, SWT.NONE);
    shell.setText("SWT Application");
    shell.setSize(500, 375);
    shell.open();
    shell.layout();
    }});

    }
    });
    是打不开的,点了没反应,可能是方法有问题也可能是本身就不能实现,仅作参考