开发者

Java SWT: How to trigger ModifyListener through source code?

I have attached a ModifyListener t开发者_Go百科o a Combo box and it works fine. But how do I trigger it through source code? Is there a better way than this?:

int selected = myCombo.getSelectionIndex();
myCombo.select(selected + 1);
myCombo.select(selected);


Programatically triggering a ModifyEvent in order to perform some GUI update (which I assume is what you're trying to do) is not really a good design.

Better to split the functionality you want to call out into a separate function and call it directly. Something like this:

private void doSomething() {
  // TODO: Something!
}

....

myCombo.addModifyListener(new ModifyListener(){

public void modifyText(ModifyEvent arg0) {
  doSomething();
}});

doSomething();

Any arguments you need to provide to your doSomething() method should be available without a ModifyEvent.

Hope this helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜