我在Applet中使用它。这是init函数的来源:
java.awt.Canvas awtParent;
setLayout(new java.awt.GridLayout(1, 1));
awtParent = new java.awt.Canvas();
add(awtParent);
display = new Display();
shell = org.eclipse.swt.awt.SWT_AWT.new_Shell(display, awtParent);
shell.setLayout(new org.eclipse.swt.layout.FillLayout());
String operatingSystem = System.getProperty("os.name").toLowerCase();
if (operatingSystem.equals("linux")) {
GLData data = new GLData ();
data.doubleBuffer = true;
canvas = new GLCanvas(shell, SWT.NONE, data);
((GLCanvas)canvas).setCurrent();
} else {
canvas = new Canvas(shell, SWT.EMBEDDED);
}
canvas.setLayout(new org.eclipse.swt.layout.FillLayout());
shell.open();
setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
validate();
System.out.println(awtParent.getBounds());
System.out.println(shell.getBounds());
System.out.println(canvas.getBounds());
和结果:
java.awt.Rectangle[x=0,y=0,width=640,height=480]
Rectangle {0, 25, 1050, 656}
Rectangle {0, 0, 0, 0}