Search code examples
javaswtcomposite

How To Find A Label In A Composite


I am trying to refresh a clabel in a composite. However the clabel does not always exist. I need a way to check if exists in the composite. I have tried the getChildren class on the composite, and I have been able to use it to find all the CLabel's on the composite,but I can't parse them.

This is what I have so far

Control[] childs = comp.getChildren();

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

    }
}

Solution

  • Why not use instanceof and then cast it?

    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 */
        }
    }