简体   繁体   English

将按钮添加到集合SWT中

[英]Adding buttons into collection SWT

I have a problem with buttons. 我的按钮有问题。 I found that when i add buttons into ArrayList, I will can manange every added button. 我发现当我将按钮添加到ArrayList中时,我可以管理每个添加的按钮。 But i don't have idea how to use setEnabled after adding it into ArrayList 但是我不知道将其添加到ArrayList后如何使用setEnabled

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

If you want all of them to setEnabled(true) then iterate through the array list as @DannyDaglas stated. 如果希望它们全部设置为setEnabled(true),则按照@DannyDaglas的说明遍历数组列表。

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

If you want to pick one of them in specific then you can enter the index of the button and setEnabled(true). 如果要特定选择其中一个,则可以输入按钮的索引并设置setEnabled(true)。

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

If you are not sure about which index it is and you have objects of the buttons then you can do something like this 如果您不确定它是哪个索引,并且有按钮的对象,则可以执行以下操作

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

Iterate over the array list with: 使用以下方法遍历数组列表:

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

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

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