2011-06-18 44 views
0

我開始使用Eclipse SWT,我有以下問題。Eclipse SWT Shell到JInternalFrame

下一課將打開一個窗口,其中包含「archivo」變量中引用的單詞文檔。

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?

感謝您的幫助。 問候!

回答

1

您正在混合兩個工具包。您的代碼使用SWT,但JInternalFrame來自Swing工具包。 SWT和Swing是如何在Java中編寫UI的兩種完全不同的方式。

There are some possibilities about how to integrate SWT and Swing,但我擔心你不能將SWT窗口「轉換」爲JInternalFrame。如果沒有別的,Window代表屏幕上的真實窗口,而JInternalFrame是Swing中所謂的輕量級對象,它不代表操作系統級別的窗口。