Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » ComboBox selection change listener issue(ComboBox gets notified with modify and selection change events even if the selection does not change)
ComboBox selection change listener issue [message #1004638] Wed, 23 January 2013 15:23 Go to next message
Levente Mising name is currently offline Levente Mising name
Messages: 3
Registered: December 2010
Junior Member
Hello,

I created a simple ComboBox with the values A, B, C, D, E in it.
I have also added a ModifyListener and an ISelectionChangeListener to it.

To my surprise, these two listeners were notified even if the selection did not actually change in the ComboBox. For example, assuming that the current selection was B, if I opened up the ComboBox and selected B again, both of the listeners were called back!

Is there any way to ensure that the listeners are only notified when the content of the ComboBox actually changes? The ComboBox was created with the SWT.DROP_DOWN style because I wanted to allow the user to edit the combo.

Best regards,
Levente


Re: ComboBox selection change listener issue [message #1005703 is a reply to message #1004638] Mon, 28 January 2013 10:49 Go to previous message
John Steele is currently offline John Steele
Messages: 49
Registered: January 2010
Member
Dude, come on, I just tested it, and it only notifies the listener when the selection index changes (i.e., the selection listener does not get notified if you select the same index within the Combo).

final Combo combo = new Combo(parent, SWT.DROP_DOWN);
combo.setItems(new String [] {"Test1", "Test2", "Test3"});
combo.addSelectionListener(new SelectionAdapter() {
	@Override
	public void widgetSelected(SelectionEvent e) {
		System.out.println("Selection: " + combo.getItem(combo.getSelectionIndex()));
	}
});

BTW, I'm using "Combo" not "ComboBox". I don't know where you're getting the "ComboBox" widget from.
Levente Mising name wrote on Wed, 23 January 2013 10:23
Hello,

I created a simple ComboBox with the values A, B, C, D, E in it.
I have also added a ModifyListener and an ISelectionChangeListener to it.

To my surprise, these two listeners were notified even if the selection did not actually change in the ComboBox. For example, assuming that the current selection was B, if I opened up the ComboBox and selected B again, both of the listeners were called back!

Is there any way to ensure that the listeners are only notified when the content of the ComboBox actually changes? The ComboBox was created with the SWT.DROP_DOWN style because I wanted to allow the user to edit the combo.

Best regards,
Levente


Previous Topic:TreeViewer Databinding issues
Next Topic:Mouse Scroll does not work in my propertysheet tab
Goto Forum:
  


Current Time: Fri Sep 19 15:52:34 GMT 2014

Powered by FUDForum. Page generated in 0.03048 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software