Bug 332887 SWT Snippets use incorrect positioning
Quoting from Steve Northover's SWT book, section 4.2: "Very often, the location of the client area within the control is (0, 0), but this is not always the case. Figure 4.3 shows the client area of two group boxes from different platforms, with Windows on the left and GTK on the right. On Windows, the location of the client area is (3, 13). On GTK, it is (0, 0)". Therefore, portable SWT code should never position widgets relative to (0, 0) but relative to the parent's client area. While on most platforms, the assumption is true, it is not in Eclipse RAP. Unfortunately, a couple of the official SWT snippets show this bad practice, which causes incorrect layouting in RAP. An example is Snippet40: Shell shell = new Shell (display); Composite c1 = new Composite (shell, SWT.BORDER); c1.setSize (100, 100); Composite c2 = new Composite (shell, SWT.BORDER); c2.setBounds (100, 0, 100, 100); To be fully portable, this code should be rewritten to: Shell shell = new Shell (display); Rectangle clientArea = shell.getClientArea(); Composite c1 = new Composite (shell, SWT.BORDER); c1.setBounds (clientArea.x, clientArea.y, 100, 100); Composite c2 = new Composite (shell, SWT.BORDER); c2.setBounds (clientArea.x + 100, clientArea.y, 100, 100);
examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet40.java
public static void main (String [] args) {
	Display display = new Display ();
	Shell shell = new Shell (display);
	Composite c1 = new Composite (shell, SWT.BORDER);
	c1.setSize (100, 100);
	Composite c2 = new Composite (shell, SWT.BORDER);
	c2.setBounds (100, 0, 100, 100);
	Menu menu = new Menu (shell, SWT.POP_UP);
	MenuItem item = new MenuItem (menu, SWT.PUSH);
	item.setText ("Popup");
	c1.setMenu (menu);
	c2.setMenu (menu);
	shell.setMenu (menu);
	shell.setSize (300, 300);
	shell.open ();
	while (!shell.isDisposed ()) {
		if (!display.readAndDispatch ()) display.sleep ();
	}
	display.dispose ();
}
}