From 65cafca3ca4cfaa5d363d1fdcf60ef110c17cede Mon Sep 17 00:00:00 2001 From: Karl Duderstadt Date: Wed, 21 Oct 2020 21:53:52 +0200 Subject: [PATCH] Update JComboBox choices during SwingChoiceWidget refresh These changes ensure JComboBox items update during DynamicCallbacks --- .../ui/swing/widget/SwingChoiceWidget.java | 38 +++++++++++++++++-- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/scijava/ui/swing/widget/SwingChoiceWidget.java b/src/main/java/org/scijava/ui/swing/widget/SwingChoiceWidget.java index 3adb50a..86d7d88 100644 --- a/src/main/java/org/scijava/ui/swing/widget/SwingChoiceWidget.java +++ b/src/main/java/org/scijava/ui/swing/widget/SwingChoiceWidget.java @@ -67,7 +67,10 @@ public void actionPerformed(final ActionEvent e) { @Override public String getValue() { - return comboBox.getSelectedItem().toString(); + if (comboBox.getItemCount() > 0) + return comboBox.getSelectedItem().toString(); + else + return null; } // -- WrapperPlugin methods -- @@ -97,8 +100,35 @@ public boolean supports(final WidgetModel model) { @Override public void doRefresh() { - final Object value = get().getValue(); - if (value.equals(comboBox.getSelectedItem())) return; // no change - comboBox.setSelectedItem(value); + final String[] choices = get().getChoices(); + + if (!areListsEqual(choices, comboBoxItems())) { + comboBox.removeAllItems(); + for (int i=0; i