Community
Participate
Working Groups
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);
Created attachment 185474 [details] SWT Snippet40 on RAP This screenshot shows how Snippet40 is rendered in RAP. In this case, the Shell's client area starts at (5, 27).
Fixed in HEAD, thank you.
(In reply to comment #0) > a couple of the official SWT snippets show this bad practice which other snippets are wrong ?
Thanks for the quick fix! A layout is of course much better than absolute positioning. (In reply to comment #3) > which other snippets are wrong ? Hmm, there are quite a lot, let's start at the beginning (it seems to get better in the newer snippets): Snippets 3, 4, 7, 9, 11, 12, 17, 18, 19, 20, 21, 22, 26, 32, 34, 35, 36, 41, 44, 45, 46, 47, 49, 52, 53, 54, 55, 56, 57, 58, 59, ... I'm not 100% sure about Snippet 5, but I think it has the same problem. BTW, just stumbled upon a "new Text (shell, 0)" in snippet 22, this should probably be replaced by a style flag.