My window should allow two different kind of layouts (it’s a simple example to better illustrate it), e.g.
+-------------+-------------+-------------+
| Component 1 | Component 2 | Component 3 |
| | | |
| | | |
| | | |
| | | |
+-------------+-------------+-------------+
and
+-------------+---------------------------+
| Component 1 | Component 2 |
| | |
| +---------------------------+
| | Component 3 |
| | |
+-------------+---------------------------+
where the user can switch between both, e.g., using a menu item.
With SWT you need to provide the parent when creating a component. But we will need to (1) reuse the component and (2) place them in a different parent (similar to docking frameworks). How is this possible with SWT?
You can simply do this by changing a component’s parent.
setParent()changes the control’s parent, if the underlying operating system supports it. Then you canlayout()the composite so the changes appear.Say you have three controls:
c1containing vertical controlsc2containing horizontal controlslblbtnHere’s the code: