Fix triggering of model after item change

This commit is contained in:
SiboVG 2024-08-07 21:40:34 +02:00
parent b0feb33459
commit 16bd21bb90

View File

@ -181,7 +181,9 @@ public class SearchableAndCategorizableComboBox<G extends Group, T extends Group
} else {
// If the model is not mutable, we need to set a new model
// This should be a rare case, as DefaultComboBoxModel is mutable
setModel(new DefaultComboBoxModel<>(new Vector<>(allItems)));
model = new DefaultComboBoxModel<>(new Vector<>(allItems));
setupModelListener(model);
setModel(model);
}
// Recreate the search fields only if they don't exist
@ -246,6 +248,7 @@ public class SearchableAndCategorizableComboBox<G extends Group, T extends Group
};
itemMenu.addActionListener(e -> {
setSelectedItem(item);
fireActionEvent();
});
groupMenu.add(itemMenu);
}
@ -304,6 +307,7 @@ public class SearchableAndCategorizableComboBox<G extends Group, T extends Group
T selectedItem = filteredList.getSelectedValue();
if (selectedItem != null) {
SearchableAndCategorizableComboBox.this.setSelectedItem(selectedItem);
fireActionEvent();
// Hide the popups after selection
hidePopups();
}
@ -425,22 +429,7 @@ public class SearchableAndCategorizableComboBox<G extends Group, T extends Group
if (model == null) {
return;
}
model.addListDataListener(new ListDataListener() {
@Override
public void intervalAdded(ListDataEvent e) {
updateItemsFromModel();
}
@Override
public void intervalRemoved(ListDataEvent e) {
updateItemsFromModel();
}
@Override
public void contentsChanged(ListDataEvent e) {
updateItemsFromModel();
}
});
model.addListDataListener(this);
addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {