如何在复合材料中找到标签

时间:2012-12-13 16:07:55

标签: java swt composite

我正在尝试刷新合成中的clabel。然而,clabel并不总是存在。我需要一种方法来检查复合中是否存在。我已经在复合上尝试了getChildren类,并且我已经能够使用它来查找复合体上的所有CLabel,但是我无法解析它们。

这是我到目前为止所拥有的

Control[] childs = comp.getChildren();

for (int i = 0; i < childs.length; i++) {
    if(childs[i].getClass().getSimpleName().equalsIgnoreCase("CLabel")){

    }
}

1 个答案:

答案 0 :(得分:2)

为什么不使用instanceof然后再施展呢?

Control[] children = comp.getChildren();

for (int i = 0; i < children.length; i++)
{
    if(children[i] instanceof CLabel)
    {
        CLabel label = (CLabel) children[i];

        /* Do something with the label */
    }
}