그리드 레이아웃은 행 레이아웃의 모델을 기반으로 명시적으로 다중 행과 다중 열을 사용할수 있게 한다. 실질적으로 그리드 레이아웃은 여러개의 선반과 깔끔한 파티션으로 칸막이한 책장을 제공하여 컨트롤들을 잘 구성하도록 도와준다.
생성자가 두 개의 매개변수를 취하는 것에 주의하자. false를 넘기면 레이아우은 각 열에 대해 필요한 최소한의 공간만을 사용한다.
GridData - RowData객체와 유사하다. 생성자는 일련의 스타일 상수를 취한다.
예를 들면..
FILL_HORIZONTAL : 비어있는 공간을 채우기 위해 셀을 수평으로 확장한다.
FILL_BOTH : 비어있는 공간을 채우기 위해 셀을 수평, 수직으로 확장한다.
VERTICAL_ALIGN_BEGINNING : 셀의 내용을 위쪽 정렬한다.
또한, GridData크기속성의 사용하게 되는데..
widthHint, heightHint,horizontalIndent,verticalSpan(그리드에서 이 셀이 차지하는 행의 개수)
package com.swtjface.ch6;
import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;
public class Ch6GreidLayout extends Composite{
public Ch6GreidLayout(Composite parent) {
super(parent, SWT.NONE)
// GridLayout layout = new GridLayout(4, false);
// setLayout(layout);
// for (int i = 0; i < 16; ++i) {
// Button button = new Button(this, SWT.NONE);
// button.setText("Cell " + i);
// }
GridLayout layout = new GridLayout(3, false);
setLayout(layout);
Button b = new Button(this, SWT.NONE);
b.setText("Button 1");
b = new Button(this, SWT.NONE);
b.setText("Button 2");
b.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
b = new Button(this, SWT.NONE);
b.setText("Button 3");
Text t = new Text(this, SWT.MULTI);
GridData data = new GridData(GridData.FILL_BOTH);
data.horizontalSpan = 2;
data.verticalSpan = 2;
t.setLayoutData(data);
b = new Button(this, SWT.NONE);
b.setText("Button 4");
b.setLayoutData(new GridData(GridData.FILL_VERTICAL));
b = new Button(this, SWT.NONE);
b.setText("Button 5");
b.setLayoutData(new GridData(GridData.FILL_VERTICAL));
}
}
import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;
public class Ch6GreidLayout extends Composite{
public Ch6GreidLayout(Composite parent) {
super(parent, SWT.NONE)
// GridLayout layout = new GridLayout(4, false);
// setLayout(layout);
// for (int i = 0; i < 16; ++i) {
// Button button = new Button(this, SWT.NONE);
// button.setText("Cell " + i);
// }
GridLayout layout = new GridLayout(3, false);
setLayout(layout);
Button b = new Button(this, SWT.NONE);
b.setText("Button 1");
b = new Button(this, SWT.NONE);
b.setText("Button 2");
b.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
b = new Button(this, SWT.NONE);
b.setText("Button 3");
Text t = new Text(this, SWT.MULTI);
GridData data = new GridData(GridData.FILL_BOTH);
data.horizontalSpan = 2;
data.verticalSpan = 2;
t.setLayoutData(data);
b = new Button(this, SWT.NONE);
b.setText("Button 4");
b.setLayoutData(new GridData(GridData.FILL_VERTICAL));
b = new Button(this, SWT.NONE);
b.setText("Button 5");
b.setLayoutData(new GridData(GridData.FILL_VERTICAL));
}
}