Class JosmComboBox<E>
- Type Parameters:
E- the type of the elements of this combo box
- All Implemented Interfaces:
ActionListener,ImageObserver,ItemSelectable,MenuContainer,PropertyChangeListener,Serializable,EventListener,Accessible,ListDataListener,PopupMenuListener
- Direct Known Subclasses:
AutoCompComboBox,OsmPrimitiveTypesComboBox
This combobox will show as many rows as possible without covering the combox itself. It makes
sure the list will never go outside the screen (see #7917). You may limit the number of rows
shown with the configuration: gui.combobox.maximum-row-count.
This combobox uses a JosmTextField for its editor component.
- Since:
- 5429 (creation), 7015 (generics for Java 7)
- See Also:
-
Nested Class Summary
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 TypeFieldDescriptionprivate Integerthe configured maximum row count or nullprivate Stringgreyed text to display in the editor when the selected value is emptyprivate intThe preferred height of the combobox when closed.static final StringLimits the number of rows that this combobox will show.Fields 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
ConstructorsConstructorDescriptionCreates aJosmComboBoxwith aJosmComboBoxModeldata model.JosmComboBox(E[] items) Creates aJosmComboBoxthat contains the elements in the specified array.JosmComboBox(JosmComboBoxModel<E> aModel) Creates aJosmComboBoxthat takes it items from an existingJosmComboBoxModeldata model. -
Method Summary
Modifier and TypeMethodDescriptionfinal voidEmpties the internal undo manager, if any.booleanReturn true if the combobox should display the hint text.Returns the editor componentReturns the string representation of current edited item, or null.getHint()Returns the hint textgetList()Get the dropdown list componentgetModel()Returns theJosmComboBoxModelcurrently used.Overrides the calculated height.getText()Returns the text in the combobox editor.private voidinit()protected voidDraw the hint text for read-only comboboxes.voidvoidvoidLimits the popup height.voidvoidvoidsetEditor(ComboBoxEditor newEditor) Sets the hint to display when no text has been entered.intsetPreferredHeight(int height) Sets the preferred height of the combobox editor.setSelectedItemText(String text) Selects an item and/or sets textvoidSets the text in the combobox editor.Methods inherited from class javax.swing.JComboBox
actionPerformed, actionPropertyChanged, addActionListener, addItem, addItemListener, addPopupMenuListener, configureEditor, configurePropertiesFromAction, contentsChanged, createActionPropertyChangeListener, createDefaultKeySelectionManager, fireActionEvent, fireItemStateChanged, firePopupMenuCanceled, firePopupMenuWillBecomeInvisible, firePopupMenuWillBecomeVisible, getAccessibleContext, getAction, getActionCommand, getActionListeners, getEditor, getItemAt, getItemCount, getItemListeners, getKeySelectionManager, getMaximumRowCount, getPopupMenuListeners, getPrototypeDisplayValue, getRenderer, getSelectedIndex, getSelectedItem, getSelectedObjects, getUI, getUIClassID, hidePopup, insertItemAt, installAncestorListener, intervalAdded, intervalRemoved, isEditable, isLightWeightPopupEnabled, isPopupVisible, paramString, processKeyBinding, processKeyEvent, removeActionListener, removeAllItems, removeItem, removeItemAt, removeItemListener, removePopupMenuListener, selectedItemChanged, selectWithKeyChar, setAction, setActionCommand, setEditable, setEnabled, setKeySelectionManager, setLightWeightPopupEnabled, setMaximumRowCount, setModel, setPopupVisible, setPrototypeDisplayValue, setRenderer, setSelectedIndex, setSelectedItem, setUI, showPopup, updateUIMethods 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, 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, 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, setUI, 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, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Field Details
-
PROP_MAXIMUM_ROW_COUNT
Limits the number of rows that this combobox will show.- See Also:
-
configMaximumRowCount
the configured maximum row count or null -
preferredHeight
The preferred height of the combobox when closed. Use if the items in the list dropdown are taller than the item in the editor, as in some comboboxes in the preset dialog. -1 to use the height of the tallest item in the list. -
hint
greyed text to display in the editor when the selected value is empty
-
-
Constructor Details
-
JosmComboBox
public JosmComboBox()Creates aJosmComboBoxwith aJosmComboBoxModeldata model. The default data model is an empty list of objects. UseaddItemto add items. By default the first item in the data model becomes selected. -
JosmComboBox
Creates aJosmComboBoxthat takes it items from an existingJosmComboBoxModeldata model.- Parameters:
aModel- the model that provides the displayed list of items
-
JosmComboBox
Creates aJosmComboBoxthat contains the elements in the specified array. By default the first item in the array (and therefore the data model) becomes selected.- Parameters:
items- an array of objects to insert into the combo box
-
-
Method Details
-
init
-
getModel
Returns theJosmComboBoxModelcurrently used. -
setEditor
-
getEditorComponent
Returns the editor component- Returns:
- the editor component
- Since:
- 9484
- See Also:
-
getEditorItemAsString
Returns the string representation of current edited item, or null.- Returns:
- the string representation of current edited item, or null
- Since:
- 18313
-
getText
Returns the text in the combobox editor.- Returns:
- the text
- Since:
- 18173
- See Also:
-
setText
Sets the text in the combobox editor.- Parameters:
value- the text to set- Since:
- 18173
- See Also:
-
setSelectedItemText
Selects an item and/or sets textSelects the item whose
toString()equalstext. If an item could not be found, selects nothing and sets the text anyway.- Parameters:
text- the text to select and set- Returns:
- the item or null
-
getHint
Returns the hint text- Returns:
- the hint text
-
setHint
Sets the hint to display when no text has been entered.- Parameters:
newHint- the hint to set- Returns:
- the old hint
- Since:
- 18221
-
setComponentOrientation
- Overrides:
setComponentOrientationin classComponent
-
displayHint
Return true if the combobox should display the hint text.- Returns:
- whether to display the hint text
- Since:
- 18221
-
getPreferredSize
Overrides the calculated height. See:setPreferredHeight(int).- Overrides:
getPreferredSizein classJComponent- Since:
- 18221
-
setPreferredHeight
Sets the preferred height of the combobox editor.A combobox editor is automatically sized to accomodate the widest and the tallest items in the list. In the Preset dialogs we show more of an item in the list than in the editor, so the editor becomes too big. With this method we can set the editor height to a fixed value.
Set this to -1 to get the default behaviour back.
See also: #6157
- Parameters:
height- the preferred height or -1- Returns:
- the old preferred height
- Since:
- 18221
- See Also:
-
getList
Get the dropdown list component- Returns:
- the list or null
-
paintComponent
Draw the hint text for read-only comboboxes.The obvious way -- to call
setText(hint)andsetForeground(gray)on theJLabelreturned by the list cell renderer -- unfortunately does not work out well because many UIs change the foreground color or the enabled state of theJLabelafter the list cell renderer has returned (BasicComboBoxUI). Other UIs don't honor the label color at all (SynthLabelUI).We use the same approach as in
JosmTextField. The only problem we face is to get the coordinates of the text inside the combobox. Fortunately even read-only comboboxes have a (partially configured) editor component, although they don't use it. We configure that editor just enough to callmodelToViewandgetBaselineon it, thus obtaining the text coordinates. -
discardAllUndoableEdits
Empties the internal undo manager, if any.Used in the
UploadDialog.- Since:
- 14977
-
popupMenuWillBecomeVisible
Limits the popup height.Limits the popup height to the available screen space either below or above the combobox, whichever is bigger. To find the maximum number of rows that fit the screen, it does the reverse of the calculation done in
BasicComboPopup.getPopupLocation().- Specified by:
popupMenuWillBecomeVisiblein interfacePopupMenuListener- See Also:
-
popupMenuWillBecomeInvisible
- Specified by:
popupMenuWillBecomeInvisiblein interfacePopupMenuListener
-
popupMenuCanceled
- Specified by:
popupMenuCanceledin interfacePopupMenuListener
-
propertyChange
- Specified by:
propertyChangein interfacePropertyChangeListener
-