Class SearchField

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class SearchField extends JPanel
Search field used by Rule Studio and AutoPvP for consistent look and behavior. Placeholder, clear button, optional result count, focus highlighting.
  • Constructor Details

    • SearchField

      public SearchField()
      A search field with the placeholder "Search...".
    • SearchField

      public SearchField(String placeholder)
      A search field showing placeholder while empty and unfocused. Escape clears it.
  • Method Details

    • setPlaceholder

      public void setPlaceholder(String placeholder)
      Changes the hint text.
    • setOnTextChanged

      public void setOnTextChanged(Consumer<String> callback)
      Called on the EDT with the current text after every key release and on clear().
    • setOnEnter

      public void setOnEnter(Runnable callback)
      Called on the EDT when Enter is released in the field.
    • getText

      public String getText()
      The current text.
    • setText

      public void setText(String text)
      Sets the text without firing the text-changed callback.
    • clear

      public void clear()
      Empties the field and fires the text-changed callback with "".
    • showCount

      public void showCount(int count, int total)
      Shows a count/total badge while the field has text; hidden when it is empty.
    • hideCount

      public void hideCount()
      Hides the result-count badge.
    • requestFocus

      public void requestFocus()
      Focuses the inner text field.
      Overrides:
      requestFocus in class JComponent
    • selectAll

      public void selectAll()
      Selects all text in the field.