-
Notifications
You must be signed in to change notification settings - Fork 235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ActionPerformed Fired when setSelection method called in WebSwitch #400
Comments
If you look at any Swing component - they all fire appropriate events even if you set the value through the code, otherwise it is impossible to track changes made in the component settings or data anyhow. Here is an actual example - public void setSelectedItem(Object anObject) {
Object oldSelection = selectedItemReminder;
Object objectToSelect = anObject;
if (oldSelection == null || !oldSelection.equals(anObject)) {
if (anObject != null && !isEditable()) {
// For non editable combo boxes, an invalid selection
// will be rejected.
boolean found = false;
for (int i = 0; i < dataModel.getSize(); i++) {
E element = dataModel.getElementAt(i);
if (anObject.equals(element)) {
found = true;
objectToSelect = element;
break;
}
}
if (!found) {
return;
}
}
// Must toggle the state of this flag since this method
// call may result in ListDataEvents being fired.
selectingItem = true;
dataModel.setSelectedItem(objectToSelect);
selectingItem = false;
if (selectedItemReminder != dataModel.getSelectedItem()) {
// in case a users implementation of ComboBoxModel
// doesn't fire a ListDataEvent when the selection
// changes.
selectedItemChanged();
}
}
fireActionEvent();
} As you can see it fires both events on the If you want to do what you mentioned in the topic - you need to ensure that second action event is ignored while first one is being handled and vice versa. I have a lot of similar workarounds for some file chooser events for example. That said, I will be doing some adjustments to |
|
I'll move |
- WebSwitch.java - `ActionListener` will not fire upon selection change from the code anymore, it will only fire evens when user is interacting with the component - WebSwitch.java - `ItemListener` can be used to detect all selection change events instead of `ActionListener` Overlay - WebLookAndFeel.java - Separated font used for `overlay` component General - Fixed typos across a few classes
I've re-checked how some other Swing components solve this problem and seems I was wrong before. I've added a solution similar to I've pushed the change into git and it will be available with v1.2.11 release soon. |
Also since this is solved - less critical |
I need to use two WebSwitchs in a Window where only one can selected at a time. So I have written a toggle method to invert the selection and called in two switchs actionPerformed event in a actionListener.
Problem is setSelection method runs actionPerformed event and StackOverFlow is happening since both of them toggling their states recursively
The text was updated successfully, but these errors were encountered: