如何在单击按钮后重新绘制swt合成以更改该合成的内容

use*_*687 5 java swt

我是SWT的新手.我正在研究的项目有一个主要的复合材料,上面有3个儿童复合材料.Upper复合材料由按钮组成,中间复合材料用于显示内容,下部复合材料用于其他目的.当我单击上部合成中的按钮时,它必须触发中间合成中的内容更改.这是我习惯做的代码

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);
}
Run Code Online (Sandbox Code Playgroud)

现在的问题是在我点击按钮并执行上面的代码之后,在我调整GUI大小之前似乎没有任何事情发生,然后中间复合的内容将出现.

drs*_*pid 6

Composite.layout()="如果接收器具有一个布局,询问布局布局 "

请注意,Layout和LayoutData是两个不同的东西.LayoutData告诉Composite如何在父级上执行操作.布局告诉Composite如何安排其子项.在您的情况下,您没有在currentCenterComposite上设置布局,因此调用layout()无效.

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