Class GhidraComboBox<E>
- Type Parameters:
E
- the item type
- All Implemented Interfaces:
GComponent
,ActionListener
,ImageObserver
,ItemSelectable
,MenuContainer
,Serializable
,EventListener
,Accessible
,ListDataListener
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. This is enabled by default.
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:
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.JComboBox
JComboBox.AccessibleJComboBox, JComboBox.KeySelectionManager
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
Field Summary
Fields inherited from class javax.swing.JComboBox
actionCommand, dataModel, editor, isEditable, keySelectionManager, lightWeightPopupEnabled, maximumRowCount, renderer, selectedItemReminder
Fields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
Fields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
Fields inherited from interface docking.widgets.GComponent
HTML_DISABLE_STRING
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
-
Constructor Summary
ConstructorDescriptionDefault constructor.GhidraComboBox
(E[] items) Construct a new GhidraComboBox and populate a default model with the given items.GhidraComboBox
(Collection<E> items) Construct a new GhidraComboBox and populate a default model with the given items.GhidraComboBox
(ComboBoxModel<E> model) Construct a new GhidraComboBox using the given model. -
Method Summary
Modifier and TypeMethodDescriptionvoid
void
Adds a document listener to the editor component's document.void
Adds a KeyListener to the combobox's editor component.void
addToModel
(E item) Adds the given item to the combobox's data model.void
addToModel
(Collection<E> items) Adds all the given item to the combobox's data model.void
associateLabel
(JLabel label) Convenience method for associating a label with the editor component.void
Removes all the items from the combobox data model.boolean
containsItem
(E item) Returns true if the combobox contains the given item.getText()
Returns the text in combobox's editor text componentvoid
void
Removes a document listener from the editor component's documentvoid
Removes a KeyListener from the combobox's editor component.void
void
Selects the text in the text field editor usd by this combo box.void
setAutoCompleteEnabled
(boolean enable) This enables or disables auto completion.void
setColumnCount
(int columnCount) Sets the size of the text field editor used by this combo box.void
setColumns
(int columns) Sets the number of column's in the editor's component (JTextField).void
setDocument
(Document document) Sets document to be used by the combobox's editor component.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').void
setSelectedItem
(Object obj) void
setSelectionEnd
(int selectionEnd) Sets the selection end in the editor's text field.void
setSelectionStart
(int selectionStart) Sets the selection start in the editor's text field.void
Sets the text on the combobox's editor text componentvoid
setUI
(ComboBoxUI ui) Methods inherited from class javax.swing.JComboBox
actionPerformed, actionPropertyChanged, addItem, addItemListener, addPopupMenuListener, configureEditor, configurePropertiesFromAction, contentsChanged, createActionPropertyChangeListener, createDefaultKeySelectionManager, fireActionEvent, fireItemStateChanged, firePopupMenuCanceled, firePopupMenuWillBecomeInvisible, firePopupMenuWillBecomeVisible, getAccessibleContext, getAction, getActionCommand, getActionListeners, getEditor, getItemAt, getItemCount, getItemListeners, getKeySelectionManager, getMaximumRowCount, getModel, getPopupMenuListeners, getPrototypeDisplayValue, getRenderer, getSelectedIndex, getSelectedItem, getSelectedObjects, getUI, getUIClassID, hidePopup, insertItemAt, installAncestorListener, intervalAdded, intervalRemoved, isEditable, isLightWeightPopupEnabled, isPopupVisible, paramString, processKeyBinding, processKeyEvent, removeAllItems, removeItem, removeItemAt, removeItemListener, removePopupMenuListener, selectedItemChanged, selectWithKeyChar, setAction, setActionCommand, setEditable, setEditor, setEnabled, setKeySelectionManager, setLightWeightPopupEnabled, setMaximumRowCount, setModel, setPopupVisible, setPrototypeDisplayValue, setRenderer, setSelectedIndex, showPopup, updateUI
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface docking.widgets.GComponent
isHTMLRenderingEnabled, setHTMLRenderingEnabled
-
Constructor Details
-
GhidraComboBox
public GhidraComboBox()Default constructor. -
GhidraComboBox
Construct a new GhidraComboBox using the given model.- Parameters:
model
- the model
-
GhidraComboBox
Construct a new GhidraComboBox and populate a default model with the given items.- Parameters:
items
- the items
-
GhidraComboBox
Construct a new GhidraComboBox and populate a default model with the given items.- Parameters:
items
- the items
-
-
Method Details
-
setUI
-
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
Returns the text in combobox's editor text component- Returns:
- the text in combobox's editor text component
-
setText
Sets the text on the combobox's editor text component- Parameters:
text
- the text to set
-
setSelectedItem
- Overrides:
setSelectedItem
in classJComboBox<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
Adds the given item to the combobox's data model.- Parameters:
item
- the item to add
-
addToModel
Adds all the given item to the combobox's data model.- Parameters:
items
- the item to add
-
containsItem
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
- Overrides:
addActionListener
in classJComboBox<E>
-
removeActionListener
- Overrides:
removeActionListener
in classJComboBox<E>
-
addEditorKeyListener
Adds a KeyListener to the combobox's editor component.- Parameters:
l
- the listener to add
-
removeEditorKeyListener
Removes a KeyListener from the combobox's editor component.- Parameters:
l
- the listener to remove
-
setDocument
Sets document to be used by the combobox's editor component.- Parameters:
document
- the document to be set
-
addDocumentListener
Adds a document listener to the editor component's document.- Parameters:
l
- the listener to add
-
removeDocumentListener
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
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 classJComponent
-
setAutoCompleteEnabled
public void setAutoCompleteEnabled(boolean enable) This enables or disables auto completion. When on, the combobox will attempt to auto-fill the input text box with drop-down items that start with the text entered. This behavior may not be desirable when the drop-down list is more than just a list of previously typed strings. Auto completion is on by default.- Parameters:
enable
- if true, auto completion is on, otherwise it is off.
-
getTextField
-