【问题标题】:How do redraw the swt composite after clicking a button to change the content of that composite单击按钮以更改该复合材料的内容后如何重绘 swt 复合材料
【发布时间】:2014-06-20 20:21:11
【问题描述】:

我是 SWT 的新手。我正在做的项目有一个主复合材料,上面有 3 个子复合材料。上组合由按钮组成,中组合用于显示内容,下组合用于其他用途。必须发生的是,当我单击上部复合材料中的按钮时,它必须触发中间复合材料中的内容更改。 这是我用来做这个的代码

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 大小之前似乎什么都没有发生,然后中间合成中的内容就会出现。

【问题讨论】:

  • 我面临着类似的问题。我有复合材料,其中有一些文本字段和按钮。我想在单击按钮时添加一个新的复选框字段。它正在被添加,但我只能在调整 UI 大小时看到。我尝试在 Composite 上调用 layout ..但这并没有做任何事情...你能告诉我你是如何解决这个问题的吗?

标签: java swt


【解决方案1】:

Composite.layout() = "如果接收者有layout,则要求layoutlayout"

请注意,Layout 和 LayoutData 是两个不同的东西。 LayoutData 告诉 Composite 如何在父级上表现。 Layout 告诉 Composite 如何排列它的子元素。在您的情况下,您没有在 currentCenterComposite 上设置布局,因此调用 layout() 无效。

尝试在你的合成上也设置一个布局。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-21
    • 1970-01-01
    • 2019-04-19
    • 2011-10-04
    • 2013-07-02
    • 1970-01-01
    相关资源
    最近更新 更多