anguspcw
anguspcw

Reputation: 306

SWT: how to find the button with SWT.RADIO style?

I have an interface contains multiple buttons, these buttons contains difference style such as SWT.RADIO, SWT.TOGGLE and SWT.NONE. How can I find all the buttons with SWT.RADIO style? Should i use the getStyle() to compare the SWT.RADIO?

Thanks.

    Control[] controls = composite.getChildren();

    for (int i = 0; i < controls.length; i++) {     
        if (controls[i] instanceof Composite) {             
            //do something
        }
        else if (controls[i] instanceof Button) {
            //How can I find all the buttons with SWT.RADIO style?

        }
    }

Upvotes: 2

Views: 229

Answers (1)

Shashwat
Shashwat

Reputation: 2352

Check out below code:

Control[] controls = composite.getChildren();
List<Button> radioBList = new ArrayList<>();
List<Button> pushBList = new ArrayList<>();
List<Button> checkBList = new ArrayList<>();

for (int i = 0; i < controls.length; i++) {     
    if (controls[i] instanceof Composite) {             
        //do something
    } else if (controls[i] instanceof Button) {
        //How can I find all the buttons with SWT.RADIO style?
        Button button = (Button) controls[i];
        int style = button.getStyle();
        if ((style & SWT.RADIO) != 0) {
            radioBList.add(button);
        } else if ((style & SWT.PUSH) != 0) {
            pushBList.add(button);
        } else if ((style & SWT.CHECK) != 0) {
            checkBList .add(button);
        }
    }
}

Upvotes: 5

Related Questions