2014-12-17 3 views
0

두 개의 테이블이있는 대화 상자를 만들고 싶습니다. 이 두 테이블은 수직 정렬에서 동일한 공간을 공유해야합니다. 테이블의 여러 요소에 스크롤바가 표시되어야합니다.GridLayout 서로 테이블 두 개

@Override 
protected Control createDialogArea(Composite parent) { 
    createSecondDialog(); 
    GridLayoutFactory layout = GridLayoutFactory.fillDefaults().numColumns(
      1); 
    GridDataFactory grid = GridDataFactory.fillDefaults().grab(true, false); 

    Composite composite = (Composite) super.createDialogArea(parent); 
    layout.applyTo(composite); 

    composite.setBackground(Display.getDefault().getSystemColor(
      SWT.COLOR_CYAN)); 

    Composite section = new Composite(composite, SWT.NONE); 
    layout.applyTo(section); 
    grid.applyTo(section); 

    createTable(section); 
    createTable(section); 

    return composite; 
} 

private TableViewer createTable(Composite area) { 
    CheckboxTableViewer table = CheckboxTableViewer.newCheckList(area, 
      SWT.READ_ONLY | SWT.FULL_SELECTION | SWT.MULTI | SWT.V_SCROLL); 

    table.getTable().setBackground(
      Display.getDefault().getSystemColor(SWT.COLOR_DARK_GRAY)); 
    GridDataFactory.fillDefaults().grab(true, false). 
      .applyTo(table.getTable()); 

    table.setLabelProvider(new LabelProvider() { 
     @Override 
     public String getText(Object element) { 
      if (element instanceof String) { 
       return (String) element; 
      } 
      return "Test"; 
     } 
    }); 

    table.setContentProvider(ArrayContentProvider.getInstance()); 
    Collection<String> input = new ArrayList<String>(); 
    fillArrayList(input); 
    table.setInput(input); 
    table.getTable().setHeaderVisible(true); 
    table.getTable().setLinesVisible(true); 

    Button copyButton = new Button(area, SWT.PUSH); 
    GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL) 
      .applyTo(copyButton); 
    copyButton.setText("Instant Copy"); 
    copyButton.addSelectionListener(new SelectionAdapter() { 

     @Override 
     public void widgetSelected(SelectionEvent selectionevent) { 
      // TODO Auto-generated method stub 

     } 
    }); 

    return table; 
} 

나는 그걸로 힘들어하고 내 requirment를 달성하기위한 답을 모른다.

도움 주셔서 감사합니다.

+1

당신이 그 말에 어떠한가이 코드? 달성하려는 것과 다른 점은 무엇입니까? – Baz

+0

테이블의 높이가 제한되지 않습니다. 테이블 당 500 개의 항목이 있으면 스크롤 막대가 표시되지 않습니다. 테이블이 창 밖으로 나옵니다. 내 욕망은 대화 상자를 얻는 것입니다 550 픽셀 heigt와이 창에서 250 픽셀의 높이 2 테이블과 테이블의 항목이 테이블이 스크롤 막대를 가져야 만 표시 할 수있는 것보다 더 많은 경우 말할 수 있습니다. – Denis

답변

1

을 무시하여 Dialog의 높이를 제한 할 수 있습니다. 그런 다음 GridLayout을 하나의 열로 사용하고 GridData을 양방향으로 확장하라는 두 테이블 모두에 설정하십시오.

public MyDialog(Shell parentShell) 
{ 
    super(parentShell); 
} 

@Override 
protected Control createDialogArea(Composite parent) 
{ 
    Composite container = (Composite) super.createDialogArea(parent); 
    container.setLayout(new GridLayout(1, false)); 

    createTable(container); 
    createTable(container); 

    return container; 
} 

private void createTable(Composite parent) 
{ 
    Table table = new Table(parent, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER); 
    table.setHeaderVisible(true); 

    TableColumn column = new TableColumn(table, SWT.NONE); 
    column.setText("Column"); 

    for (int i = 0; i < 500; i++) 
    { 
     new TableItem(table, SWT.NONE).setText("Item " + i); 
    } 

    column.pack(); 

    table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); 
} 

@Override 
protected boolean isResizable() 
{ 
    return true; 
} 

@Override 
protected void configureShell(Shell newShell) 
{ 
    super.configureShell(newShell); 
    newShell.setText("StackOverflow"); 
} 

@Override 
protected Point getInitialSize() 
{ 
    return new Point(450, 300); 
} 

public static void main(String[] args) 
{ 
    new MyDialog(new Shell()).open(); 
} 

는 다음과 같습니다 : 다음은 그 예이다

enter image description here

관련 문제