Java by API/org.eclipse.swt.layout/GridLayout

Материал из Java эксперт
Версия от 14:43, 31 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

FormLayout: marginHeight

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class MainClass {
  public static void main(String[] a) {
    Display display = new Display();
    Shell shell = new Shell(display);
    FormLayout layout = new FormLayout();
    layout.marginHeight = 5;
    layout.marginWidth = 10;
    shell.setLayout(layout);
    new Button(shell, SWT.PUSH).setText("Button");
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) {
        display.sleep();
      }
    }
    display.dispose();
  }
}





FormLayout: marginWidth

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class MainClass {
  public static void main(String[] a) {
    Display display = new Display();
    Shell shell = new Shell(display);
    FormLayout layout = new FormLayout();
    layout.marginHeight = 5;
    layout.marginWidth = 10;
    shell.setLayout(layout);
    new Button(shell, SWT.PUSH).setText("Button");
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) {
        display.sleep();
      }
    }
    display.dispose();
  }
}





GridLayout: makeColumnsEqualWidth

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class MainClass {
  public static void main(String[] a) {
    Display display = new Display();
    Shell shell = new Shell(display);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    layout.makeColumnsEqualWidth = true;
    shell.setLayout(layout);
    GridData data = new GridData(GridData.FILL_BOTH);
    Button one = new Button(shell, SWT.PUSH);
    one.setText("one");
    one.setLayoutData(data);
    data = new GridData(GridData.FILL_BOTH);
    Button two = new Button(shell, SWT.PUSH);
    two.setText("two");
    two.setLayoutData(data);
    data = new GridData(GridData.FILL_BOTH);
    Button three = new Button(shell, SWT.PUSH);
    three.setText("three");
    three.setLayoutData(data);
    data = new GridData(GridData.FILL_BOTH);
    Button four = new Button(shell, SWT.PUSH);
    four.setText("four");
    four.setLayoutData(data);
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) {
        display.sleep();
      }
    }
    display.dispose();
  }
}





GridLayout: numColumns

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class MainClass {
  public static void main(String[] a) {
    Display d = new Display();
    Shell s = new Shell(d);
    s.setSize(250,250);
    s.setText("A GridLayout Example");
    GridLayout gl = new GridLayout();
    gl.numColumns=3;
    s.setLayout(gl);
    Label l1 = new Label(s, SWT.BORDER);
    l1.setText("Column One");
    final Label l2 = new Label(s, SWT.BORDER);
    l2.setText("Column Two");
    final Label l3 = new Label(s, SWT.BORDER);
    l3.setText("Column Three");
    Text t1 = new Text(s, SWT.SINGLE | SWT.BORDER);
    Text t2 = new Text(s, SWT.SINGLE | SWT.BORDER);
    Text t3 = new Text(s, SWT.SINGLE | SWT.BORDER);
    Text t4 = new Text(s, SWT.SINGLE | SWT.BORDER);
    Text t5 = new Text(s, SWT.SINGLE | SWT.BORDER);
    Text t6 = new Text(s, SWT.SINGLE | SWT.BORDER);
    s.open();
    while (!s.isDisposed()) {
      if (!d.readAndDispatch())
        d.sleep();
    }
    d.dispose();
  }
}





new GridLayout()

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class MainClass {
  public static void main(String[] a) {
    Display d = new Display();
    Shell s = new Shell(d);
    s.setSize(250,250);
    s.setText("A GridLayout Example");
    GridLayout gl = new GridLayout();
    gl.numColumns=3;
    s.setLayout(gl);
    Label l1 = new Label(s, SWT.BORDER);
    l1.setText("Column One");
    final Label l2 = new Label(s, SWT.BORDER);
    l2.setText("Column Two");
    final Label l3 = new Label(s, SWT.BORDER);
    l3.setText("Column Three");
    Text t1 = new Text(s, SWT.SINGLE | SWT.BORDER);
    Text t2 = new Text(s, SWT.SINGLE | SWT.BORDER);
    Text t3 = new Text(s, SWT.SINGLE | SWT.BORDER);
    Text t4 = new Text(s, SWT.SINGLE | SWT.BORDER);
    Text t5 = new Text(s, SWT.SINGLE | SWT.BORDER);
    Text t6 = new Text(s, SWT.SINGLE | SWT.BORDER);
    s.open();
    while (!s.isDisposed()) {
      if (!d.readAndDispatch())
        d.sleep();
    }
    d.dispose();
  }
}