2013-12-11 43 views
0

我创建的应用程序具有两个部分:如何拉伸SWT中的compoiste布局?

 1. tree viewer 
     2. table viewer + messages 

它看起来像

    ------------------------------- 
       - tree -   table - 
       -   -     - 
       -   - -----------------    
       -   -     - 
       -   - messages  -  
       ------------------------------- 

,正确的部分(表和消息不伸展直到象的第一部分的端部)的问题

它看起来像

    ------------------------------- 
       - tree -   table - 
       -   - -----------------    - 
       -   -     - 
           meesages  -  
       -   -------------------- 
       -   -    
       ------------- 

这是代码

 SashForm sashForm = new SashForm(parent, SWT.HORIZONTAL); 
    Composite treeComposite = new Composite(sashForm, SWT.BORDER); 
    Composite detailsCompositePart = new Composite(sashForm, SWT.NONE); 

    GridLayout detailsGridLayout = new GridLayout(); 
    detailsGridLayout.numColumns = 1; 
    detailsCompositePart.setLayout(detailsGridLayout); 

    GridData detailsPartGridData = new GridData(SWT.FILL, SWT.FILL, true, true); 
    detailsCompositePart.setLayoutData(detailsPartGridData); 

    detailsComposite = new Composite(detailsCompositePart, SWT.BORDER); 
    GridLayout detailsSideGridLayout = new GridLayout(); 
    detailsSideGridLayout.numColumns = 1; 
    detailsComposite.setLayout(detailsSideGridLayout); 
    GridData detailsGridData = new GridData(SWT.FILL, SWT.FILL, true, true); 
    detailsComposite.setLayoutData(detailsGridData); 

    messageComposite = new Composite(detailsComposite, SWT.NONE); 

    GridLayout messageGridLayout = new GridLayout(); 
    messageGridLayout.numColumns = 1; 
    messageComposite.setLayout(messageGridLayout); 
    GridData messageGridData = new GridData(SWT.FILL, SWT.END, true, false); 
    messageComposite.setLayoutData(messageGridData); 



    labelError = new Label(messageGridData , SWT.NONE); 
    GridData data = new GridData(SWT.FILL, SWT.END, true, false); 
    data.heightHint = 30; 
    labelError.setLayoutData(data); 
    //labelError.setText("Message!!!!!!!!!!!!!!"); //$NON-NLS-1$ 

回答

1

没有完整的代码,很难说出发生了什么。

下面是一些代码,应该可以帮助您:

public static void main(String[] args) 
{ 
    Display display = new Display(); 
    Shell shell = new Shell(display); 
    shell.setLayout(new GridLayout(1, false)); 
    shell.setText("StackOverflow"); 

    Composite horizontal = new Composite(shell, SWT.NONE); 
    horizontal.setLayout(new GridLayout(2, false)); 
    horizontal.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); 

    Composite left = new Composite(horizontal, SWT.BORDER); 
    left.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); 

    Composite right = new Composite(horizontal, SWT.NONE); 
    GridLayout layout = new GridLayout(1, false); 
    layout.marginHeight = 0; 
    layout.marginWidth = 0; 
    right.setLayout(layout); 
    right.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); 

    Composite top = new Composite(right, SWT.BORDER); 
    top.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); 

    Composite bottom = new Composite(right, SWT.BORDER); 
    bottom.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); 

    shell.pack(); 
    shell.setSize(600, 400); 
    shell.open(); 

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

    display.dispose(); 
} 

是这样的:

enter image description here

如果这不是你在找什么,请更新更多详情您的问题/码。

+0

但我添加ridData detailsGridData = new GridData(); detailsGridData.horizo​​ntalAlignment = SWT.FILL; detailsGridData.grabExcessHorizo​​ntalSpace = true; detailsGridData.verticalAlignment = SWT.FILL; detailsGridData.grabExcessVerticalSpace = true; detailsComposite.setLayoutData(detailsGridData); – user1365697

+0

@ user1365697更新了我的答案。 – Baz

+0

可以在没有SashForm的情况下完成吗? – user1365697