Java Tutorial/SWT/FillLayout — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
Admin (обсуждение | вклад) м (1 версия) |
(нет различий)
|
Текущая версия на 15:19, 31 мая 2010
Содержание
Configure the layout orientation: HORIZONTAL and VERTICAL
The possible values for type: SWT.HORIZONTAL, SWT.VERTICAL
SWT.HORIZONTAL: lays the controls in a single row SWT.VERTICAL: lays the controls in a single column.
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class FillLayoutHorizontal {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout(SWT.HORIZONTAL));
new Button(shell, SWT.PUSH).setText("one");
new Button(shell, SWT.PUSH).setText("two");
new Button(shell, SWT.PUSH).setText("three");
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
}
Define the margins and spacing properties
The default (initial) value of each property is 0.
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class MarginSpaceProperties {
public static void main(String[] args) {
Display display = new Display();
final Shell shell = new Shell(display);
FillLayout fillLayout = new FillLayout(SWT.HORIZONTAL);
// Width of horizontal margins placed along the left and right edges
fillLayout.marginWidth = 5;
// Height of vertical margins placed along the top and bottom edges
fillLayout.marginHeight = 5;
shell.setLayout(fillLayout);
Button button1 = new Button(shell, SWT.PUSH);
button1.setText("button1");
Button button2 = new Button(shell, SWT.PUSH);
button2.setText("button number 2");
Button button3 = new Button(shell, SWT.PUSH);
button3.setText("3");
shell.setSize(450, 100);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
}
Set spacing properties
The default (initial) value of each property is 0.
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class LayoutSpaceProperties {
public static void main(String[] args) {
Display display = new Display();
final Shell shell = new Shell(display);
FillLayout fillLayout = new FillLayout(SWT.HORIZONTAL);
fillLayout.marginWidth = 5;
fillLayout.marginHeight = 5;
// Number of pixels between the edge of a cell and edges of its neighboring cells
fillLayout.spacing = 10;
shell.setLayout(fillLayout);
Button button1 = new Button(shell, SWT.PUSH);
button1.setText("button1");
Button button2 = new Button(shell, SWT.PUSH);
button2.setText("button number 2");
Button button3 = new Button(shell, SWT.PUSH);
button3.setText("3");
shell.setSize(450, 100);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
}
Using FillLayout
- FillLayout lays out controls into a single row or column (without wrap).
- FillLayout forces all the children to be the same size.
- FillLayout places the children into the whole client area of a composite.
You can specify the margins and spacing properties. FillLayout has no layout data. The primary usage of FillLayouts is laying out controls in task bars and toolbars.
It places all controls in either a single column or a single row, and makes them all the same size.
FillLayout Constructors:
ConstructorDescriptionpublic FillLayout()Constructs a FillLayout and sets type to SWT.HORIZONTAL.public FillLayout(int type)Constructs a FillLayout and sets type to the passed type.