From af56159c6460ab42f06e30d4e677c67f64e3ea8e Mon Sep 17 00:00:00 2001 From: Kevin Lamonte Date: Mon, 11 Feb 2019 14:32:27 -0600 Subject: [PATCH] Fix set value --- src/jexer/TComboBox.java | 24 +++++++++++++++++++++--- src/jexer/TList.java | 10 ++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/jexer/TComboBox.java b/src/jexer/TComboBox.java index 5748c36..0814177 100644 --- a/src/jexer/TComboBox.java +++ b/src/jexer/TComboBox.java @@ -282,11 +282,29 @@ public class TComboBox extends TWidget { * @param text the new text in the edit field */ public void setText(final String text) { + setText(text, true); + } + + /** + * Set combobox text value. + * + * @param text the new text in the edit field + * @param caseSensitive if true, perform a case-sensitive search for the + * list item + */ + public void setText(final String text, final boolean caseSensitive) { field.setText(text); for (int i = 0; i < list.getMaxSelectedIndex(); i++) { - if (list.getSelected().equals(text)) { - list.setSelectedIndex(i); - return; + if (caseSensitive == true) { + if (list.getListItem(i).equals(text)) { + list.setSelectedIndex(i); + return; + } + } else { + if (list.getListItem(i).toLowerCase().equals(text.toLowerCase())) { + list.setSelectedIndex(i); + return; + } } } list.setSelectedIndex(-1); diff --git a/src/jexer/TList.java b/src/jexer/TList.java index da60af1..0ed7a07 100644 --- a/src/jexer/TList.java +++ b/src/jexer/TList.java @@ -406,6 +406,16 @@ public class TList extends TScrollableWidget { selectedString = index; } + /** + * Get a selectable string by index. + * + * @param idx index into list + * @return the string at idx in the list + */ + public final String getListItem(final int idx) { + return strings.get(idx); + } + /** * Get the selected string. * -- 2.27.0