I’m starting to work with Eclipse SWT and I have the following questions.
The next class opens a window with the word document referenced in the “archivo” variable.
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();
}
}
How can I do to make that window be a JInternalFrame?
Thanks for the help.
Greetings!
You are mixing two toolkits. Your code is using SWT, but
JInternalFrameis coming from Swing toolkit. SWT and Swing are two completely different ways how to code UI in Java.There are some possibilities about how to integrate SWT and Swing, but I am afraid that you cannot just “convert” SWT Window into JInternalFrame. If for nothing else, Window represents real window on screen while JInternalFrame is so-called lightweight object in Swing, it doesn’t represent window at OS level.