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 { } else {
// If the model is not mutable, we need to set a new model // If the model is not mutable, we need to set a new model
// This should be a rare case, as DefaultComboBoxModel is mutable // 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 // 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 -> { itemMenu.addActionListener(e -> {
setSelectedItem(item); setSelectedItem(item);
fireActionEvent();
}); });
groupMenu.add(itemMenu); groupMenu.add(itemMenu);
} }
@ -304,6 +307,7 @@ public class SearchableAndCategorizableComboBox<G extends Group, T extends Group
T selectedItem = filteredList.getSelectedValue(); T selectedItem = filteredList.getSelectedValue();
if (selectedItem != null) { if (selectedItem != null) {
SearchableAndCategorizableComboBox.this.setSelectedItem(selectedItem); SearchableAndCategorizableComboBox.this.setSelectedItem(selectedItem);
fireActionEvent();
// Hide the popups after selection // Hide the popups after selection
hidePopups(); hidePopups();
} }
@ -425,22 +429,7 @@ public class SearchableAndCategorizableComboBox<G extends Group, T extends Group
if (model == null) { if (model == null) {
return; return;
} }
model.addListDataListener(new ListDataListener() { model.addListDataListener(this);
@Override
public void intervalAdded(ListDataEvent e) {
updateItemsFromModel();
}
@Override
public void intervalRemoved(ListDataEvent e) {
updateItemsFromModel();
}
@Override
public void contentsChanged(ListDataEvent e) {
updateItemsFromModel();
}
});
addActionListener(new ActionListener() { addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {