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()
    • 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, if that is the type of editor used. By default the editor for combo boxes is a text field. This method is a convenience for the user to set the number of columns on that text field, which updates the preferred size of the combo box.
      Parameters:
      columnCount - The number of columns for the text field editor
      See Also:
    • selectAll

      public void selectAll()
    • clearModel

      public void clearModel()
    • addToModel

      public void addToModel(E obj)
    • addToModel

      public void addToModel(Collection<E> items)
    • containsItem

      public boolean containsItem(E obj)
    • addActionListener

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

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

      public void addDocumentListener(DocumentListener l)
    • removeDocumentListener

      public void removeDocumentListener(DocumentListener l)