Second section standard layout
2.1. FillLayout
FillLayout is the easiest layout class that puts the component in a row or a column and enforces the component size. In general, the height of the component is consistent with the highest component, the width is consistent with the widest component. FillLayout is not folded, and the boundary distance and spacing cannot be set. It can be used to lay out of the task bar or toolbar, or a set of selection boxes in Group. It can also be used when the container has only one sub-assembly. For example, if a shell has only one group sub-component, FillLayout will make the group full of shells.
The following is the relevant code. First create a FillLayout, then set its TYPE domain value to swt.vertical, set it to the container (a shell). Example of the shell has three buttons, B1, B2, and Button 3. Note that in FillLayout, all subcomponents are identical and full of space available:
FillLayout FillLayout = New FillLayout ();
FillLayout.Type = SWT.VERTICAL;
Shell.setLayout (FillLayout);
New Button (shell, swt.push) .Settext ("b1");
New Button (Shell, Swt.push) .Settext ("Wide Button 2");
New Button (Shell, Swt.push) .Settext ("Button 3");
The following figure shows the difference between the horizontal and vertical layout, and after the initial state and the adjustment size, the different performance of FillLayout:
Initial state
After adjusting the size
FillLayout.Type = SWT.HORIZONTAL (Default)
FillLayout.Type = SWT.Vertical
2.2 RowLayout
RowLayout is more common than FillLayout, which provides folding display, and can set boundary distance and spacing. It has several domains that can be set. In addition, each component can be set to setLayoutData method to set the size of their size.
2.2.1 RowLayout's setup domain
TYPE (* 2.0 new addition *)
The TYPE domain controls RowLayout is a level or vertical layout assembly. The default is horizontal layout.
WRAP
WRAP domain controls whether ROWLAYOUT does not have enough space when there is no sufficient space. Default flap display.
Pack
When the Pack Domain is True, the component uses their original size and is arranged away from the left (AND the Will BE Aligned as far to the left as possible?). If the Pack field is false, the component will populate the available space and similar to FillLayout. The default is True.
Justify
When the Justify domain is TRUE, the component will extend from left to right within the available space. If the container becomes large, then excess space is allocated onto the component. If PACK and JUSTIFY are set to TRUE, the components will keep their original size, and excess space is allocated on the gap between the components. The default False.
Marginleft, Margintop, Marginright, Marginbottom, Spacing
The distance between these domain control components (spacing, with pixels), and the margins between components and containers. The default, RowLayout retains the margins and spacing of 3 pixels. The figure below shows the margin and spacing: 2.2.2 RowLayout Example The following code creates a RowLayout and sets each domain as a default value, then set it to a shell: RowLayout RowLayout = new RowLayout (); RowLayout.wrap = false; rowLayout.pack = false; rowLayout.justify = true; rowLayout.type = SWT.VERTICAL; rowLayout.marginLeft = 5; rowLayout.marginTop = 5; rowLayout.marginRight = 5; rowLayout.marginBottom = 5; rowLayout.spacing = 0; shell.setLayout (RowLayout); if you use the default setting, you only need a line of code: shell.setLayout (new rowLayout ()); the following figure shows the result of setting different domain values:
After the initial state adjustment, Wrap = true pack = true justify = false type = swart horizontal (default)
Wrap = FALSE (tailoring when there is enough space)
Pack = false (all components are identiform)
Justify = true (component stretches according to available space)
TYPE = SWT.Vertical (Component vertically arranged)