Class DropDownTextField<T>

Type Parameters:
T - The type of object that this model manipulates
All Implemented Interfaces:
GComponent, ImageObserver, MenuContainer, Serializable, Accessible, Scrollable, SwingConstants
Direct Known Subclasses:
DropDownSelectionTextField

public class DropDownTextField<T> extends JTextField implements GComponent
A text field that handles comparing text typed by the user to the list of objects and then presenting potential matches in a drop down window. The items in this window cannot be selected.

This class will fire fireEditingStopped() and fireEditingCancelled() events when the user makes a choice by pressing the ENTER key, thus allowing the client code to use this class similar in fashion to a property editor. This behavior can be configured to:

This class is subclassed to not only have the matching behavior, but to also allow for user selections.

See Also:
  • Field Details Link icon

    • PREVIEW_WINDOW_BGCOLOR Link icon

      protected static final Color PREVIEW_WINDOW_BGCOLOR
    • PREVIEW_WINDOW_FGCOLOR Link icon

      protected static final Color PREVIEW_WINDOW_FGCOLOR
    • list Link icon

      protected DropDownTextField<T>.DropDownList list
    • dataModel Link icon

      protected final DropDownTextFieldDataModel<T> dataModel
    • internallyDrivenUpdate Link icon

      protected boolean internallyDrivenUpdate
  • Constructor Details Link icon

    • DropDownTextField Link icon

      public DropDownTextField(DropDownTextFieldDataModel<T> dataModel)
      Constructor.

      Uses the default refresh delay of 350ms.

      Parameters:
      dataModel - provides element storage and search capabilities to this component.
    • DropDownTextField Link icon

      public DropDownTextField(DropDownTextFieldDataModel<T> dataModel, int updateMinDelay)
      Constructor.
      Parameters:
      dataModel - provides element storage and search capabilities to this component.
      updateMinDelay - suggestion list refresh delay, triggered after search results have changed. Too low a value may cause an inconsistent view as filtering tasks complete; too high a value delivers an unresponsive user experience.
  • Method Details Link icon

    • createListSelectionModel Link icon

      protected ListSelectionModel createListSelectionModel()
    • setPreviewPaneAttributes Link icon

      protected void setPreviewPaneAttributes()
    • setSelectedItems Link icon

      protected void setSelectedItems()
    • getPreviewListener Link icon

      protected ListSelectionListener getPreviewListener()
    • getPreviewPaneComponent Link icon

      protected JComponent getPreviewPaneComponent()
    • setText Link icon

      public void setText(String text)
      Overridden to allow for the setting of text without showing the completion window. This is useful for setting the current value to be edited before the using initiates editing.
      Overrides:
      setText in class JTextComponent
      Parameters:
      text - The text to set on this text field.
    • setTextWithoutClosingCompletionWindow Link icon

      protected void setTextWithoutClosingCompletionWindow(String text)
    • hasPreview Link icon

      protected boolean hasPreview()
    • getMatchingData Link icon

      protected List<T> getMatchingData(String searchText)
    • isMatchingListShowing Link icon

      public boolean isMatchingListShowing()
    • setConsumeEnterKeyPress Link icon

      public void setConsumeEnterKeyPress(boolean consume)
      When true, this field will not pass Enter key press events up to it's parent when the drop-down selection window is open. However, an Enter key press will still be "unconsumed" when the drop-down window is not open. When set to false, this method will always pass the Enter key press up to it's parent.

      The default is true. Clients will set this to false when they wish to respond to an Enter event. For example, a dialog may want to close itself on an Enter key press, even when the drop-down selection text field is still open. Contrastingly, when this field is embedded inside of a larger editor, like a multi-editor field dialog, the Enter key press should simply trigger the drop-down window to close and the editing to stop, but should not trigger the overall dialog to close.

      Parameters:
      consume - true to consume
    • setIgnoreEnterKeyPress Link icon

      public void setIgnoreEnterKeyPress(boolean ignore)
      True signals to do nothing when the user presses Enter. The default is to respond to the Enter key, using any existing selection to set this field's selected value.

      This can be set to true to allow clients to show drop-down matches without allowing the user to select them, triggering the window to be closed.

      Parameters:
      ignore - true to ignore Enter presses; false is the default
    • setMatchingWindowHeight Link icon

      public void setMatchingWindowHeight(int height)
      Sets the height of the matching window. The default value is 300.
      Parameters:
      height - the new height
    • addDropDownSelectionChoiceListener Link icon

      public void addDropDownSelectionChoiceListener(DropDownSelectionChoiceListener<T> listener)
      Adds a listener that will be called back when the user makes a choice from the drop-down list. A choice is a user action that triggers the selection window to be closed and updates the text field.

      Note: the listener is stored in a weak data structure, so you must maintain a reference to the listener you pass in--anonymous classes or lambdas will not work.

      Parameters:
      listener - the listener
    • addCellEditorListener Link icon

      public void addCellEditorListener(CellEditorListener listener)
      Adds a listener to be notified when cell editing is canceled or completed.
      Parameters:
      listener - The listener to add
      Throws:
      IllegalArgumentException - if the listener has already been added
    • removeCellEditorListener Link icon

      public void removeCellEditorListener(CellEditorListener listener)
      Removes the given listener from this class if it has previously been added.
      Parameters:
      listener - The listener to remove.
    • setTextFromList Link icon

      protected void setTextFromList()
    • shouldReplaceTextFieldTextWithSelectedItem Link icon

      protected boolean shouldReplaceTextFieldTextWithSelectedItem(String textFieldText, T selectedItem)
    • getSelectedValue Link icon

      public T getSelectedValue()
      Returns the user's selection or null if the user has not made a selection.

      Note: the value returned from this method may not match the text in the field in the case that the user has selected a value and then typed some text.

      Returns:
      the user's selection or null if the user has not made a selection.
    • setSelectedValue Link icon

      public void setSelectedValue(T value)
      Sets the current selection on this text field. This will store the provided value and set the text of the text field to be the name of that value. If the given value is null, then the text of this field will be cleared.
      Parameters:
      value - The value that is to be the current selection or null to clear the selected value of this text field.
    • closeDropDownWindow Link icon

      public void closeDropDownWindow()
      Closes the drop down window
    • hideMatchingWindow Link icon

      protected void hideMatchingWindow()
    • setTextFromSelectedListItemAndKeepMatchingWindowOpen Link icon

      protected void setTextFromSelectedListItemAndKeepMatchingWindowOpen()