Class SearchList<T>

Type Parameters:
T - the type of items in the list
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class SearchList<T> extends JPanel
Component for displaying and selecting from a filterable list of items that are grouped into categories. Similar to a JList, but with filtering and grouping.
See Also:
  • Constructor Details

    • SearchList

      public SearchList(SearchListModel<T> model, BiConsumer<T,String> chosenItemCallback)
      Construct a new SearchList given a model and an chosen item callback.
      Parameters:
      model - the model containing the group list items
      chosenItemCallback - the callback to be notified when an item is chosen (enter key pressed)
  • Method Details

    • getFilterText

      public String getFilterText()
      Returns the current filter text
      Returns:
      the current filter text
    • getModel

      public SearchListModel<T> getModel()
      Returns the search list model.
      Returns:
      the model
    • setFilterText

      public void setFilterText(String text)
      Sets the current filter text
      Parameters:
      text - the text to set as the current filter
    • getSelectedItem

      public T getSelectedItem()
      Gets the currently selected item.
      Returns:
      the currently selected item.
    • setSelectedItem

      public void setSelectedItem(T t)
    • setSelectionCallback

      public void setSelectionCallback(Consumer<T> consumer)
      Sets a consumer to be notified whenever the selected item changes.
      Parameters:
      consumer - the consumer to be notified whenever the selected item changes.
    • setItemRenderer

      public void setItemRenderer(ListCellRenderer<SearchListEntry<T>> itemRenderer)
      Sets a custom sub-renderer for displaying list items. Note: this renderer is only used to render the item, not the category.
      Parameters:
      itemRenderer - the sub_renderer for rendering the list items, but not the entire line which includes the category.
    • setInitialSelection

      public void setInitialSelection()
      Resets the selection to the first element
    • setShowCategories

      public void setShowCategories(boolean b)
      Sets an option to display categories in the list or not.
      Parameters:
      b - true to show categories, false to not shoe them
    • setSingleClickMode

      public void setSingleClickMode(boolean b)
      Sets an option for the list to respond to either double or single mouse clicks. By default, it responds to a double click.
      Parameters:
      b - true for single click mode, false for double click mode
    • setDisplayNameFunction

      public void setDisplayNameFunction(BiFunction<T,String,String> nameFunction)
    • setMouseHoverSelection

      public void setMouseHoverSelection()
    • dispose

      public void dispose()
      Disposes the component and clears all the model data
    • moveListUpDown

      protected void moveListUpDown(boolean isUp)
    • chooseItem

      public void chooseItem()
    • createFilter

      protected BiPredicate<T,String> createFilter(String text)
    • getFilterField

      public JTextField getFilterField()