Class GhidraComboBox<E>

Type Parameters:
E - the item type
All Implemented Interfaces:
GComponent, ActionListener, ImageObserver, ItemSelectable, MenuContainer, Serializable, EventListener, Accessible, ListDataListener

public class GhidraComboBox<E> extends JComboBox<E> implements GComponent
GhidraComboBox adds the following features:

1) ActionListeners are only invoked when the <Enter> key is pressed within the text-field of the combo-box. In normal JComboBox case, the ActionListeners are notified when an item is selected from the list.

2) Adds the auto-completion feature. As a user types in the field, the combo box suggest the nearest matching entry in the combo box model.

It also fixes the following bug:

A normal JComboBox has a problem (feature?) that if you have a dialog with a button and JComboBox and you edit the comboText field and then hit the button, the button sometimes does not work.

When the combobox loses focus, and its text has changed, it generates an actionPerformed event as though the user pressed <Enter> in the combo text field. This has a bizarre effect if you have added an actionPerformed listener to the combobox and in your callback you adjust the enablement state of the button that you pressed (which caused the text field to lose focus) in that you end up changing the button's internal state(by calling setEnabled(true or false)) in the middle of the button press.

See Also:
  • Constructor Details

    • GhidraComboBox

      public GhidraComboBox()
      Default constructor.
    • GhidraComboBox

      public GhidraComboBox(ComboBoxModel<E> model)
      Construct a new GhidraComboBox using the given model.
      Parameters:
      model - the model
    • GhidraComboBox

      public GhidraComboBox(E[] items)
      Construct a new GhidraComboBox and populate a default model with the given items.
      Parameters:
      items - the items
    • GhidraComboBox

      public GhidraComboBox(Collection<E> items)
      Construct a new GhidraComboBox and populate a default model with the given items.
      Parameters:
      items - the items
  • Method Details

    • setUI

      public void setUI(ComboBoxUI ui)
      Overrides:
      setUI in class JComboBox<E>
    • setEnterKeyForwarding

      public void setEnterKeyForwarding(boolean forwardEnter)
      HACK ALERT: By default, the JComboBoxUI forwards the <Enter> key actions to the root pane of the JComboBox's container (which is used primarily by any installed 'default button'). The problem is that the forwarding does not happen always. In the case that the <Enter> key will trigger a selection in the combo box, the action is NOT forwarded.

      By default Ghidra disables the forwarding altogether, since most users of GhidraComboBox will add an action listener to handle <Enter> actions.

      To re-enable the default behavior, set the forwardEnter value to true.

      Parameters:
      forwardEnter - true to enable default <Enter> key handling.
    • getText

      public String getText()
      Returns the text in combobox's editor text component
      Returns:
      the text in combobox's editor text component
    • setText

      public void setText(String text)
      Sets the text on the combobox's editor text component
      Parameters:
      text - the text to set
    • setSelectedItem

      public void setSelectedItem(Object obj)
      Overrides:
      setSelectedItem in class JComboBox<E>
    • setColumnCount

      public void setColumnCount(int columnCount)
      Sets the size of the text field editor used by this combo box.
      Parameters:
      columnCount - The number of columns for the text field editor
      See Also:
    • selectAll

      public void selectAll()
      Selects the text in the text field editor usd by this combo box.
      See Also:
    • clearModel

      public void clearModel()
      Removes all the items from the combobox data model.
    • addToModel

      public void addToModel(E item)
      Adds the given item to the combobox's data model.
      Parameters:
      item - the item to add
    • addToModel

      public void addToModel(Collection<E> items)
      Adds all the given item to the combobox's data model.
      Parameters:
      items - the item to add
    • containsItem

      public boolean containsItem(E item)
      Returns true if the combobox contains the given item.
      Parameters:
      item - the item to check
      Returns:
      true if the combobox contains the given item.
    • addActionListener

      public void addActionListener(ActionListener l)
      Overrides:
      addActionListener in class JComboBox<E>
    • removeActionListener

      public void removeActionListener(ActionListener l)
      Overrides:
      removeActionListener in class JComboBox<E>
    • addEditorKeyListener

      public void addEditorKeyListener(KeyListener l)
      Adds a KeyListener to the combobox's editor component.
      Parameters:
      l - the listener to add
    • removeEditorKeyListener

      public void removeEditorKeyListener(KeyListener l)
      Removes a KeyListener from the combobox's editor component.
      Parameters:
      l - the listener to remove
    • setDocument

      public void setDocument(Document document)
      Sets document to be used by the combobox's editor component.
      Parameters:
      document - the document to be set
    • addDocumentListener

      public void addDocumentListener(DocumentListener l)
      Adds a document listener to the editor component's document.
      Parameters:
      l - the listener to add
    • removeDocumentListener

      public void removeDocumentListener(DocumentListener l)
      Removes a document listener from the editor component's document
      Parameters:
      l - the listener to remove
    • setColumns

      public void setColumns(int columns)
      Sets the number of column's in the editor's component (JTextField).
      Parameters:
      columns - the number of columns to show
      See Also:
    • associateLabel

      public void associateLabel(JLabel label)
      Convenience method for associating a label with the editor component.
      Parameters:
      label - the label to associate
    • setSelectionStart

      public void setSelectionStart(int selectionStart)
      Sets the selection start in the editor's text field.
      Parameters:
      selectionStart - the start of the selection
      See Also:
    • setSelectionEnd

      public void setSelectionEnd(int selectionEnd)
      Sets the selection end in the editor's text field.
      Parameters:
      selectionEnd - the end of the selection
      See Also:
    • requestFocus

      public void requestFocus()
      Overrides:
      requestFocus in class JComponent