[英]How do I create an eclipse toolbar item with SWT.RADIO style with drop-down capabilities?
[英]SWT: how to find the button with SWT.RADIO style?
我有一個包含多個按鈕的界面,這些按鈕包含差異樣式,例如SWT.RADIO,SWT.TOGGLE和SWT.NONE。 如何找到具有SWT.RADIO樣式的所有按鈕? 我應該使用getStyle()比較SWT.RADIO嗎?
謝謝。
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?
}
}
查看以下代碼:
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);
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.