Skip to content

Commit

Permalink
ArrayEditorBuilder: select no combobox value if the initial value is …
Browse files Browse the repository at this point in the history
…not present
  • Loading branch information
bwRavencl committed May 11, 2024
1 parent 9f84c61 commit f66b72e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,11 @@ public void setLongPress(final boolean longPress) {
}

public void setMode(final Mode mode) {
modeUuid = mode.getUuid();
if (mode != null) {
modeUuid = mode.getUuid();
} else {
modeUuid = null;
}
}

public void setToggle(final boolean toggle) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.io.Serial;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JComboBox;
Expand All @@ -40,9 +41,16 @@ abstract class ArrayEditorBuilder<T> extends EditorBuilder {

@Override
public void buildEditor(final JPanel parentPanel) {
comboBox = new JComboBox<>(getValues());
final var values = getValues();

comboBox = new JComboBox<>(values);
comboBox.setAction(new JComboBoxSetPropertyAction(action, setterMethod));
comboBox.setSelectedItem(initialValue);
if (initialValue != null && Arrays.stream(values).noneMatch(initialValue::equals)) {
comboBox.setSelectedItem(null);
} else {
comboBox.setSelectedItem(initialValue);
}

parentPanel.add(comboBox);
}

Expand Down

0 comments on commit f66b72e

Please sign in to comment.