2011-11-14 3 views
0

Eclipse rcp의 Scrollable Composite에 여러 캔버스를 그려서 그리드 레이 아웃에 배치해야합니다. 나는 이것을 달성 할 수 있었지만 GridLayouts 셀 크기를 조정해야했습니다.GridLayout의 셀 크기 조정 - 여러 캔버스 그리기?

그리드는 각 캔버스의 크기를 동적으로 조정하거나 적어도 수동으로 크기를 설정하지만 GridLayout이 부모 구성 요소의 전체 공간을 채우도록합니다. 내가 지금까지 무엇을 가지고

는 :

public class Test { 
    public static void main(final String[] args) { 
    final Display display = new Display(); 
    final Shell shell = new Shell(display); 

    shell.setLayout(new FillLayout()); 

    final ScrolledComposite sComp = new ScrolledComposite(shell, SWT.H_SCROLL | SWT.V_SCROLL); 
    final Composite fillComp = new Composite(sComp, SWT.NONE); 

    GridLayoutFactory.createFrom(new GridLayout(10, true)).applyTo(fillComp); 

    for (int i = 0; i < 500; i++) { 
     final Canvas c = new Canvas(fillComp, SWT.DOUBLE_BUFFERED); 
     c.addPaintListener(new PaintListener() { 
     public void paintControl(PaintEvent e) { 
      e.gc.setBackground(display.getSystemColor(new Random().nextInt(20))); 
      e.gc.fillRectangle(0, 0, 200, 200); 
     } 
     }); 
    } 

    sComp.setContent(fillComp); 

    fillComp.pack(); 
    shell.open(); 
    shell.pack(); 
    while (!shell.isDisposed()) { 
     if (!display.readAndDispatch()) { 
     display.sleep(); 
     } 
    } 
    } 
} 

나는 FillLayout에 부모 구성 요소의 레이아웃을 설정하는 것은 트릭을 할 것이라고 가정하지만 작동하지 않습니다. GridData 객체로 작업해야한다고 생각합니다. 그러나 여기서는 약간의 손실이 있습니다.

답변

0

두 개의 GridData 개체를 만들고 값을 설정할 수 있습니다. 하나는 비활성 셀이고 다른 하나는 활성 셀입니다. 예를 들면 :

c.setLayoutData(Active); 

또는

c.setLayoutData(Deactive); 
:

GridData Acrive = new GridData(); 
Active.widthHint = 200; 
Active.heightHint = 200; 

GridData Deactive = new GridData(); 
Deactive.widthHint = 100; 
Deactive.heightHint = 100; 

다음 리스너 방법에 당신처럼 설정된 LayoutData하여 현재 캔버스 세포 크기를 관리 할 수 ​​있습니다