Class JComboBoxConfigurableLookUp
- All Implemented Interfaces:
ActionListener,ImageObserver,ItemSelectable,MenuContainer,Serializable,EventListener,Accessible,ListDataListener
A configurable combo box component that lists items that carry out with the criterions of a ILookUp agent,
considering the text in its inner editor.
Key features:
- Allows configure it's behaviour.
- Inherits from JComboBox.
- Has 6 flags to configure its behaviour.
- It's made according the MVC (Model-View-Controller) pattern.
- Uses a
DefaultComboBoxConfigurableLookUpModelas a dataModel, which it's also configurable.
Configuration flags:
- OnlyOneColorOnText: uses red if there is no item or only items that matches with the text written according the
ILookUpagent, or uses always black color. - BeepEnabled: rings a beep sound if there is no item that matches with the text written according the
ILookUpagent, or not. - HidePopupIfThereAreNoItems: hides popup (list box) if there is no item that matches with the text written according the
ILookUpagent, or uses the default (JComboBox and more) behaviour. - ToForceSelectAnItem: forces to select an item (if the component looses the focus or user presses the Enter keyboard key), or uses the default (JComboBox and more) behaviour.
- CompleteArrowKeySelection: writes in the editor the value of the element selected by the arrow keys (up or down) if its enabled, otherwise holds the previous text.
- DisplayAllItemsWithArrowButton: true: displays all this component's dataModel items if its popup it's hided, and this component's dataModel listed only the matches
(flag:
DefaultComboBoxConfigurableLookUpModel.showAllItemsInListBox == false); otherwise, if this flag isn't enabled, won't display all items in that situation.
Default flag values are:
- OnlyOneColorOnText: false.
- BeepEnabled: false.
- HidePopupIfThereAreNoItems: true.
- ToForceSelectAnItem: true.
- CompleteArrowKeySelection: false.
- DisplayAllItemsWithArrowButton: true.
More information about the behaviour of it's dataModel in DefaultComboBoxConfigurableLookUpModel .
- Version:
- 07/02/2008
- Author:
- Pablo Piqueras Bartolomé
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassInner class that inherits of the class PlainDocument, and is used for manipulate the textWritten that has the document of the editor of this component.Nested classes/interfaces inherited from class javax.swing.JComboBox
JComboBox.AccessibleJComboBox, JComboBox.KeySelectionManagerNested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponentNested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainerNested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final booleanstatic final booleanstatic final booleanstatic final booleanstatic final booleanstatic final booleanFields inherited from class javax.swing.JComboBox
actionCommand, dataModel, editor, isEditable, keySelectionManager, lightWeightPopupEnabled, maximumRowCount, renderer, selectedItemReminderFields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWFields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor without parameters.JComboBoxConfigurableLookUp(Object[] items) Default constructor with an array of objects as parameter.JComboBoxConfigurableLookUp(Vector<Object> items) Default constructor with a Vector of objects as parameter.Default constructor with aDefaultComboBoxConfigurableLookUpModelas parameter. -
Method Summary
Modifier and TypeMethodDescriptionvoidprotected voidConfigures the component and some of its elements.protected voidConfigures the document of the editor of this component.protected voidconfigureEditor(ComboBoxEditor newEditor) Configures the editor (ComboBoxEditor) of this component.protected voidconfigurePopUp(JComboBoxConfigurableLookUp comboBox) Configures the popup of this component.protected JComboBox.KeySelectionManagerReturns the listener invoked when user presses the arrow button of thisJComboBox.protected voidThis method sets the start values of inner attributes and creates the necessary inner objects.booleanReturns the 'beep_Enabled' configuration value of this component.booleanDetermines if the popup of this component will always remain hided.booleanReturns the 'completeArrowKeySelection' configuration value of this component.booleanReturns the 'displayAllItemsWithArrowButton' configuration value of this component.booleanReturns the 'hidePopupIfThereAreNoItems' configuration value of this component.booleanReturns the 'only_One_Color_On_Text' configuration value of this component.booleanReturns the 'toForceSelectAnItem' configuration value of this component.protected StringvoidvoidvoidremoveItem(Object anObject) voidremoveItemAt(int anIndex) booleanselectWithKeyChar(char keyChar) voidsetBeepEnabled(boolean b) Sets the 'beep_Enabled' configuration value for this component.voidsetBlockPopupHided(boolean b) Sets if the popup of this component will always remain hided, or can be shown when is invoked.voidsetCompleteArrowKeySelection(boolean b) Sets the 'completeArrowKeySelection' configuration value for this component.protected voidSets the default values of the flags.voidsetDisplayAllItemsWithArrowButton(boolean b) Sets the 'toForceSelectAnItem' configuration value for this component.voidsetEditable(boolean b) voidsetEditor(ComboBoxEditor anEditor) Sets the editor used to paint and edit the selected item in theJComboBoxfield.voidsetHidePopupIfThereAreNoItems(boolean b) Sets the 'hidePopupIfThereAreNoItems' configuration value for this component.voidsetModel(ComboBoxModel aModel) voidsetOnlyOneColorOnText(boolean b) Sets the 'only_One_Color_On_Text' configuration value for this component.voidsetSelectedIndex(int anIndex) voidsetSelectedItem(Object anObject) voidsetToForceSelectAnItem(boolean b) Sets the 'toForceSelectAnItem' configuration value for this component.protected voidsetUI(ComponentUI newUI) voidvoidupdateUI()Methods inherited from class javax.swing.JComboBox
actionPerformed, actionPropertyChanged, addActionListener, addItemListener, addPopupMenuListener, configureEditor, configurePropertiesFromAction, contentsChanged, createActionPropertyChangeListener, 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, processKeyBinding, removeActionListener, removeItemListener, removePopupMenuListener, selectedItemChanged, setAction, setActionCommand, setEnabled, setKeySelectionManager, setLightWeightPopupEnabled, setMaximumRowCount, setPopupVisible, setPrototypeDisplayValue, setRenderer, setUIMethods 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, 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, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, updateMethods 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, validateTreeMethods 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
-
Field Details
-
DEFAULT_ONLY_ONE_COLOR_ON_TEXT_CONFIGURATION
public static final boolean DEFAULT_ONLY_ONE_COLOR_ON_TEXT_CONFIGURATION- See Also:
-
DEFAULT_BEEP_ENABLED_CONFIGURATION
public static final boolean DEFAULT_BEEP_ENABLED_CONFIGURATION- See Also:
-
DEFAULT_HIDE_POPUP_IF_THERE_ARE_NO_ITEMS_CONFIGURATION
public static final boolean DEFAULT_HIDE_POPUP_IF_THERE_ARE_NO_ITEMS_CONFIGURATION- See Also:
-
DEFAULT_TO_FORCE_SELECT_AN_ITEM_CONFIGURATION
public static final boolean DEFAULT_TO_FORCE_SELECT_AN_ITEM_CONFIGURATION- See Also:
-
DEFAULT_COMPLETE_ARROW_KEY_SELECTION_CONFIGURATION
public static final boolean DEFAULT_COMPLETE_ARROW_KEY_SELECTION_CONFIGURATION- See Also:
-
DEFAULT_DISPLAY_ALL_ITEMS_WITH_ARROW_BUTTON_CONFIGURATION
public static final boolean DEFAULT_DISPLAY_ALL_ITEMS_WITH_ARROW_BUTTON_CONFIGURATION- See Also:
-
-
Constructor Details
-
JComboBoxConfigurableLookUp
public JComboBoxConfigurableLookUp()Default constructor without parameters.
-
JComboBoxConfigurableLookUp
Default constructor with a
DefaultComboBoxConfigurableLookUpModelas parameter.- Parameters:
aModel- javax.swing.ComboBoxModel
-
JComboBoxConfigurableLookUp
Default constructor with an array of objects as parameter.
- Parameters:
items- An array of objects. All them must implement a 'String toStrin()' method
-
JComboBoxConfigurableLookUp
Default constructor with a Vector of objects as parameter.
- Parameters:
items- AVectorof objects. All them must implement a 'String toStrin()' method
-
-
Method Details
-
initialize
protected void initialize()This method sets the start values of inner attributes and creates the necessary inner objects.
- Parameters:
dataModel- dataModel used by this combo box instance
-
configure
protected void configure()Configures the component and some of its elements.
-
configureEditor
Configures the editor (
ComboBoxEditor) of this component.- Parameters:
newEditor- The new editor to configure
-
configureDocument
protected void configureDocument()Configures the document of the editor of this component.
-
configurePopUp
Configures the popup of this component.
- Parameters:
comboBox- A reference of this component
-
getArrowMouseListener
Returns the listener invoked when user presses the arrow button of this
JComboBox.- Returns:
- java.awt.event.MouseListener
-
setDefaultBehaviorFlagsConfiguration
protected void setDefaultBehaviorFlagsConfiguration()Sets the default values of the flags.
-
setEditor
Sets the editor used to paint and edit the selected item in the
JComboBoxfield. The editor is used only if the receivingJComboBoxis editable. If not editable, the combo box uses the renderer to paint the selected item.The editor must be a
JTextComponent, and its document aPlainDocumentobject. -
setModel
-
setSelectedIndex
public void setSelectedIndex(int anIndex) - Overrides:
setSelectedIndexin classJComboBox
-
setSelectedItem
- Overrides:
setSelectedItemin classJComboBox
-
setEditable
public void setEditable(boolean b) - Overrides:
setEditablein classJComboBox
-
removeAllItems
public void removeAllItems()- Overrides:
removeAllItemsin classJComboBox
-
addItem
-
removeItem
- Overrides:
removeItemin classJComboBox
-
removeItemAt
public void removeItemAt(int anIndex) - Overrides:
removeItemAtin classJComboBox
-
setUI
- Overrides:
setUIin classJComponent
-
selectWithKeyChar
public boolean selectWithKeyChar(char keyChar) - Overrides:
selectWithKeyCharin classJComboBox
-
processKeyEvent
- Overrides:
processKeyEventin classJComboBox
-
createDefaultKeySelectionManager
- Overrides:
createDefaultKeySelectionManagerin classJComboBox
-
paramString
- Overrides:
paramStringin classJComboBox
-
updateUI
public void updateUI() -
showPopup
public void showPopup() -
setBlockPopupHided
public void setBlockPopupHided(boolean b) Sets if the popup of this component will always remain hided, or can be shown when is invoked.
- Parameters:
b-trueif will remain blocked;falseif can be shown
-
isBlockPopupHided
public boolean isBlockPopupHided()Determines if the popup of this component will always remain hided.
- Parameters:
b-trueif will remain blocked;falseif can be shown
-
isOnlyOneColorOnText
public boolean isOnlyOneColorOnText()Returns the 'only_One_Color_On_Text' configuration value of this component. Configuration values are:
- true: always uses black colour on text.
- false: by default uses black colour on text, but if text written by user doesn't match with any item according the
ILookUpagent, text will be on red colour.
- Returns:
- 'only_One_Color_On_Text' configuration
-
setOnlyOneColorOnText
public void setOnlyOneColorOnText(boolean b) Sets the 'only_One_Color_On_Text' configuration value for this component. Configuration values are:
- true: always uses black colour on text.
- false: by default uses black colour on text, but if text written by user doesn't match with any item according the
ILookUpagent, text will be on red colour.
- Parameters:
b- value for 'only_One_Color_On_Text' configuration flag
-
isBeepEnabled
public boolean isBeepEnabled()Returns the 'beep_Enabled' configuration value of this component. Configuration values are:
- true: a beep-sound is listened when no item matches with the text written according the
ILookUpagent. - false: no sound is listened.
- Returns:
- 'beep_Enabled' configuration
- true: a beep-sound is listened when no item matches with the text written according the
-
setBeepEnabled
public void setBeepEnabled(boolean b) Sets the 'beep_Enabled' configuration value for this component. Configuration values are:
- true: a beep-sound is listened when no item matches with the text written according the
ILookUpagent. - false: no sound is listened.
- Parameters:
b- value for 'beep_Enabled' configuration flag
- true: a beep-sound is listened when no item matches with the text written according the
-
isHidePopupIfThereAreNoItems
public boolean isHidePopupIfThereAreNoItems()Returns the 'hidePopupIfThereAreNoItems' configuration value of this component. Configuration values are:
- true: hides the popup if there are no items when you write.
- false: default behaviour (if there are no items when you write, popup remains visible) .
- Returns:
- 'hidePopupIfThereAreNoItems' configuration
-
setHidePopupIfThereAreNoItems
public void setHidePopupIfThereAreNoItems(boolean b) Sets the 'hidePopupIfThereAreNoItems' configuration value for this component. Configuration values are:
- true: hides the popup if there are no items when you write.
- false: default behaviour (if there are no items when you write, popup remains visible) .
- Parameters:
b- value for 'hidePopupIfThereAreNoItems' configuration flag
-
isToForceSelectAnItem
public boolean isToForceSelectAnItem()Returns the 'toForceSelectAnItem' configuration value of this component. Configuration values are:
- true: selects the previous selected item or the first of the list when user presses the Enter key or when the component loses the focus .
- false: default behaviour .
- Returns:
- 'toForceSelectAnItem' configuration
-
setToForceSelectAnItem
public void setToForceSelectAnItem(boolean b) Sets the 'toForceSelectAnItem' configuration value for this component. Configuration values are:
- true: selects the previous selected item or the first of the list when user presses the Enter key or when the component loses the focus .
- false: default behaviour .
- Parameters:
value- for 'toForceSelectAnItem' configuration flag
-
isCompleteArrowKeySelection
public boolean isCompleteArrowKeySelection()Returns the 'completeArrowKeySelection' configuration value of this component. Configuration values are:
- true: writes in the editor the value of the element selected by the arrow keys (up or down).
- false: holds the previous text written .
- Returns:
- 'completeArrowKeySelection' configuration
-
setCompleteArrowKeySelection
public void setCompleteArrowKeySelection(boolean b) Sets the 'completeArrowKeySelection' configuration value for this component. Configuration values are:
- true: writes in the editor the value of the element selected by the arrow keys (up or down).
- false: holds the previous text written .
- Parameters:
b- value for 'completeArrowKeySelection' configuration flag
-
isDisplayAllItemsWithArrowButton
public boolean isDisplayAllItemsWithArrowButton()Returns the 'displayAllItemsWithArrowButton' configuration value of this component. Configuration values are:
- true: displays all this component's dataModel items if its popup it's hided, and this component's dataModel
listed only the matches (flag:
DefaultComboBoxConfigurableLookUpModel.showAllItemsInListBox == false). - false: normal behaviour according the other flags.
- Returns:
- 'displayAllItemsWithArrowButton' configuration
- true: displays all this component's dataModel items if its popup it's hided, and this component's dataModel
listed only the matches (flag:
-
setDisplayAllItemsWithArrowButton
public void setDisplayAllItemsWithArrowButton(boolean b) Sets the 'toForceSelectAnItem' configuration value for this component. Configuration values are:
- true: displays all this component's dataModel items if its popup it's hided, and this component's dataModel
listed only the matches (flag:
DefaultComboBoxConfigurableLookUpModel.showAllItemsInListBox == false). - false: normal behaviour according the other flags.
- Parameters:
value- for 'displayAllItemsWithArrowButton' configuration flag
- true: displays all this component's dataModel items if its popup it's hided, and this component's dataModel
listed only the matches (flag:
-