I have attached a ModifyListener
to 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);
I have attached a ModifyListener
to 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.