그리드 레이아웃(GridLayout)
그리드 레이아웃은 행 레이아웃(RowLayout)의 모델을 기반으로 여러개의 행과 열을 사용할 수 있습니다.
GridLayout의 생성자는 두 개의 매개 변수를 가집니다. 첫 번째 매개 변수는 열의 개수를 의미하여, 두 번째 매개 변수는 열의 공간을 균등하게 사용할지에 대한 부울 값입니다. 두 번째 매개 변수에 false를 설정하면, 각 열에 대해 필요한 최소한의 공간만을 사용하는 것입니다.
▶ 예제코드
| 
1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 | 
package com.swtjface.Ch6; 
import org.eclipse.swt.SWT; 
import org.eclipse.swt.layout.GridLayout; 
import org.eclipse.swt.widgets.Button; 
import org.eclipse.swt.widgets.Composite; 
public class Ch6GridLayoutComposite extends Composite { 
  public Ch6GridLayoutComposite(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<10?"0"+i:i)); 
  } 
 } 
} | 
| 
1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
27 | 
package com.swtjface.Ch6; 
import org.eclipse.jface.window.ApplicationWindow; 
import org.eclipse.swt.widgets.Composite; 
import org.eclipse.swt.widgets.Control; 
import org.eclipse.swt.widgets.Display; 
public class GridLayoutTest extends ApplicationWindow { 
 public GridLayoutTest() { 
  super(null); 
 } 
  protected Control createContents(Composite parent) { 
  Ch6GridLayoutComposite ca = new Ch6GridLayoutComposite(parent); 
   getShell().setText("Widget Window"); 
  return parent; 
 } 
  public static void main(String[] args) { 
  GridLayoutTest tc = new GridLayoutTest(); 
  tc.setBlockOnOpen(true); 
  tc.open(); 
  Display.getCurrent().dispose(); 
 } 
} | 

 
댓글 없음:
댓글 쓰기