2010-05-27 103 views
5

我是SWT的新手。我正在研究的这个项目有一个主要的复合材料,上面有3个孩子。上部组合由按钮组成,中间组合用于显示内容,下部组合用于其他目的。发生什么事情是,当我点击上层复合中的一个按钮时,它必须触发中间复合中的内容更改。 这就是我用来做这个如何在单击按钮后重新绘制swt复合图案以更改该复合图案的内容

public void widgetSelected(SelectionEvent e) { 
    /* Retrieve the contents that are currently in middle composite*/ 
    Composite currentCenterComposite = EMWindow.getCenterCompsiteState(); 
    /* Retrieve the main composite*/ 
    Composite outerComposite=EMWindow.getOuterCompsiteState(); 
    if ((currentCenterComposite != null) && (!currentCenterComposite.isDisposed())) { 
    /* Remove children that are already laid out */ 
    Object[] children = currentCenterComposite.getChildren(); 
    for (int i = 0; i < children.length; i++) { 
((Composite)children[i]).dispose(); 
    } 
    } 

    currentCenterComposite = new CenterComp(currentCenterComposite); 
    GridData gd_centerComposite = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1); 
    gd_centerComposite.minimumHeight = 50; 
    currentCenterComposite.setLayoutData(gd_centerComposite); 
    currentCenterComposite.layout(true); 
    //currentOuterComposite.layout(); 
    outerComposite.layout(true); 
} 

现在的问题是后,我按一下按钮,上面的代码的代码被执行,似乎没有发生,直到我调整界面,然后在中间复合材料中的含量会出现。

+0

我正面临类似的问题。我有复合材料,它有一些文本字段和按钮。我想在点击一个按钮时添加一个新的复选框。它正在增加,但我只能看到调整UI的大小。 我试着在Composite上调用布局..但是这并没有做任何事...你能告诉我你是如何解决这个问题的。 – 2016-08-25 07:16:39

回答

6

Composite.layout()=“如果接收机具有布局,询问布局铺陈

注意,布局和LayoutData是两个不同的东西。 LayoutData告诉Composite如何在父级上行为。布局告诉复合材料如何安排其子女。在你的情况下,你不是在currentCenterComposite上设置布局,因此调用layout()不起作用。

尝试在复合材料上设置布局。