Professional Documents
Culture Documents
LAYOUT ADN
COMPOSITE
1. LAYOUT
When writing applications in SWT, you may need to use layouts to give your
windows a specific look. A layout controls the position and size of children in a
Composite. Layout classes are subclasses of the abstract class Layout. SWT
provides several standard layout classes, and you can write custom layout classes.
The standard layout classes in the SWT library are:
· FillLayout – lays out equal-sized widgets in a single row or column.
· RowLayout – lays out widgets in a row or rows, with fill, wrap, and spacing
options.
· GridLayout – lays out widgets in a grid.
· FormLayout – lays out widgets by creating attachments for each of their sides.
· ......
StackLayout – only displays the topmost controls.
1.1 FILLLAYOUT
FillLayout is the simplest layout class. It fills the entire container with components
in a row or column and enforces a consistent size of components. Typically, the
widgets will all be as tall as the tallest widget, and as wide as the widest.
FillLayout does not wrap, and you cannot specify margins or spacing. You might
use it to lay out buttons in a task bar or tool bar, or to stack checkboxes in a Group.
c1 = new ScrolledComposite(shell,
SWT.BORDER);
expanding button:
c1.setExpandHorizontal(true);
c1.setExpandVertical(true);
The use method of CTabFloder is similar with TabFolder, and the function is more powerful, for
example:
With close button:
CTabFolder cf=new CTabFolder(shell,SWT.CLOSE);
With border:
new CTabFolder(shell,SWT.BORDER);
Here's the code
2.6 CBANNER
CBanner is used in the workbench to layout the toolbar area and perspective
switching toolbar. It draws a separator between the left and right children which
can be dragged to resize the right control.