我的问题很简单:我有一个 swt 组合,如果第一次选择该组合,我必须做一些事情,如果第一次选择其他时间,我必须做其他事情。抱歉,我是新手,我不知道该怎么做。监听器位于内部类中:
combo_agrupacion1.addSelectionListener(new GroupListener());
class GroupListener extends SelectionAdapter {
@Override
public void widgetSelected(SelectionEvent evento) {
}
}
最佳答案
您找不到内置的解决方案。您能做的最好的事情是:
首先创建一个变量,例如:
private boolean wasSelectedAlready = false;
然后在您的 widgetSelected()
函数中以 if
开头:
if (!wasSelectedAlready) {
wasSelectedAlready = true; //your function will not execute it
//is main body ever again
do anything else you ever wanted to do in this function
}
关于java - 如何检测组合选择是否是第一次选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32603162/