Eclipse SWT Shell到JInternalFrame

问题描述

| 我开始使用Eclipse SWT,并且遇到以下问题。 下一类将打开一个窗口,其中在\“ archivo \”变量中引用了单词document。
import java.io.File;

import javax.swing.JInternalFrame;

import org.eclipse.swt.SWT;
import org.eclipse.swt.SWTError;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.ole.win32.OleClientSite;
import org.eclipse.swt.ole.win32.OleFrame;
import org.eclipse.swt.widgets.display;
import org.eclipse.swt.widgets.Shell;

public class ArchivoMSOffice {

    protected static OleClientSite clientSite;
    protected static OleFrame frame;

    public ArchivoMSOffice() {

    }

    public void run(archivo) {      
        display display = new display();
        final Shell shell = new Shell(display);
        shell.setText(archivo);
        shell.setLayout(new FillLayout());
        try {
            frame = new OleFrame(shell,SWT.NONE);
            //esto abre un documento existente
            clientSite = new OleClientSite(frame,SWT.NULL,new File(archivo));
        } catch (SWTError e) {
            System.out.println(\"Unable to open activeX control\");
            display.dispose();
            return;
        }
        shell.setSize(800,600);
        shell.open();//this open de Window

        while (!shell.isdisposed()) {
            if (!display.readAnddispatch())
                display.sleep();
        }
        display.dispose();
    }
}
如何使该窗口成为JInternalFrame? 谢谢您的帮助。 问候!     

解决方法

        您正在混合使用两个工具箱。您的代码使用的是SWT,但是
JInternalFrame
来自Swing工具包。 SWT和Swing是用Java编写UI的两种完全不同的方法。 关于如何将SWT和Swing集成在一起,存在一些可能性,但恐怕您不能仅仅将SWT窗口“转换”到JInternalFrame中。如果没有别的,Window代表屏幕上的真实窗口,而JInternalFrame是Swing中的所谓轻量级对象,则它不代表OS级别的窗口。