我是 SWT 的新手。我正在从事的项目有一个主要的复合 Material ,上面有 3 个子复合 Material 。上层复合体由按钮组成,中间复合体用于显示内容,下层复合体用于其他目的。必须发生的是,当我单击上方复合 Material 中的按钮时,它必须触发中间复合 Material 中的内容更改。 这是我用来执行此操作的代码
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);
}
现在的问题是在我点击按钮并执行上面的代码之后,似乎什么都没有发生,直到我调整 GUI 的大小,然后中间组合中的内容才会出现。
最佳答案
Composite.layout() = "如果接收器有一个布局,要求布局布局"
请注意 Layout 和 LayoutData 是两个不同的东西。 LayoutData 告诉 Composite 如何在父级上运行。 Layout 告诉 Composite 如何安排它的 child 。在您的情况下,您没有在 currentCenterComposite 上设置布局,因此调用 layout() 无效。
尝试在您的复合 Material 上也设置一个布局。
关于java - 单击按钮更改该组合的内容后如何重绘 swt 组合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2919297/