Skip to content

Commit d40832c

Browse files
committed
SwingObjectWidget: guard versus empty choices list
The choices list might be non-null but empty. We guard against this in various other places, but the test here was missing. So let's add it. Hopefully this addresses the bug of empty choice dropdowns!
1 parent cbc9ef6 commit d40832c

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/main/java/org/scijava/ui/swing/widget/SwingObjectWidget.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,11 @@ public Object getValue() {
7878
public void set(final WidgetModel model) {
7979
super.set(model);
8080

81-
String[] availableChoices = model.getChoices();
82-
if (availableChoices != null) {
83-
comboBox = new JComboBox<>(availableChoices);
84-
} else {
81+
String[] choices = model.getChoices();
82+
if (choices != null && choices.length > 0) {
83+
comboBox = new JComboBox<>(choices);
84+
}
85+
else {
8586
comboBox = new JComboBox<>(model.getObjectPool().toArray());
8687
}
8788
setToolTip(comboBox);
@@ -96,8 +97,10 @@ public void set(final WidgetModel model) {
9697

9798
@Override
9899
public boolean supports(final WidgetModel model) {
99-
return super.supports(model) && ((model.getChoices() != null && model.getChoices().length>0) ||
100-
((model.getObjectPool() != null) && (model.getObjectPool().size() > 0)));
100+
return super.supports(model) && (
101+
(model.getChoices() != null && model.getChoices().length > 0) ||
102+
(model.getObjectPool() != null && model.getObjectPool().size() > 0)
103+
);
101104
}
102105

103106
// -- AbstractUIInputWidget methods ---

0 commit comments

Comments
 (0)