繁体   English   中英

将按钮添加到集合SWT中

[英]Adding buttons into collection SWT

我的按钮有问题。 我发现当我将按钮添加到ArrayList中时,我可以管理每个添加的按钮。 但是我不知道将其添加到ArrayList后如何使用setEnabled

public ArrayList<Button> buttons = new ArrayList();
buttons.add(newButton)

如果希望它们全部设置为setEnabled(true),则按照@DannyDaglas的说明遍历数组列表。

for(Button button : buttonList)
    button.setEnabled(true);

如果要特定选择其中一个,则可以输入按钮的索引并设置setEnabled(true)。

int index = 0;
buttonList.get(index).setEnabled(true);

如果您不确定它是哪个索引,并且有按钮的对象,则可以执行以下操作

int i;
for (i=0;i<buttonList.size();i++){
    if(buttonList.get(i).equals(closeButton))
    buttonList.get(i).setEnabled(true);
}

使用以下方法遍历数组列表:

for(Button button : buttons)
    button.setEnabled(true);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM