Holger's Java API

## com.antelmann.util.gui
Class JMultipleSelectionComboBox

    java.lang.Object
      java.awt.Component
          java.awt.Container
              javax.swing.JComponent
                  javax.swing.JComboBox
                      com.antelmann.util.gui.JMultipleSelectionComboBox

All Implemented Interfaces:
  Enabled, ActionListener, ImageObserver, ItemSelectable, MenuContainer, Serializable, EventListener, Accessible, ListDataListener

    public class JMultipleSelectionComboBox

extends JComboBox
implements Enabled

a specialized JComboBox allowing to deal with multiple selection. This special JComboBox - upon double-mouse-click - provides a multiple-select search list that is reflected in the JComboBox's method `JComboBox.getSelectedObjects()` and displays a special multiple-select object when a multiple selection is present. It uses a `DefaultComboBoxModel`, which may at times contain a special 'multipleSelect'-Object. Note that `getSelectedItem()` may return an irritating value (a 'multiple-select' object), which indicates that there is a multiple selection present; thus it is recommended to always call `getSelectedObjects()` to obtain the correct selection. This class does not implement `EditableComponent` as the semantics are different than the implementation of the method names in a JComboBox; instead, `setEditable(boolean)` is disabled for this implementation. Note: be careful not to use renderer that cannot deal with the multiple selection!

Since:
  05.11.2010, 23:15:45
Author:
  Holger Antelmann
See Also:
  `FormattedCellRenderer.wrapForFormatException(java.text.Format)`, Serialized Form

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
`accessibleContext, 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
`BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT`

Fields inherited from interface com.antelmann.util.Enabled
`FILTER`

Fields inherited from interface java.awt.image.ImageObserver
`ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH`

Constructor Summary
`JMultipleSelectionComboBox(Collection<?> items, Object... initialSelection)`
`JMultipleSelectionComboBox(Object[] items, Object... initialSelection)`
`JMultipleSelectionComboBox(String dialogTitle, Object[] items, Object... initialSelection)`

Method Summary
`boolean` `containsAllSelect()`
`boolean` `containsNoSelect()`
`boolean` `containsSpecialSelectionOption(String title)`
`protected JPopupMenu` `createPopupMenu()`
`Object[]` `getContainedElements(Object... objects)` returns those objects from the given array that are also elements of this model
`ListCellRenderer` `getDialogRenderer()`
`String` `getDialogTitle()`
`Object[]` `getItems()`
`DefaultComboBoxModel` `getModel()`
`Object` `getSelectedItem()` Deprecated. use `getSelectedObjects()` instead
`Object[]` `getSelectedObjects()`
`JMultipleSelectionComboBox` `insertAllSelectOption()` puts a special item at the top of the list model that allows to select all entries (if it didn't already exist)
`JMultipleSelectionComboBox` `insertNoSelectOption()` puts a special item at the top of the list model that allows to select no entries (if it didn't already exist)
`JMultipleSelectionComboBox` `insertSpecialSelectionOption(String title, Object... selection)` puts a special item at the top of the list model that allows to select a given predefined selection by a name
`boolean` `isAllowNoSelection()` if false, the dialog prevents returning with no selected elements
`boolean` `removeAllSelectOption()` removes the 'select all' option if it existed
`boolean` `removeNoSelectOption()` removes the 'no selection' option if it existed
`boolean` `removeSpecialSelectionOption(String title)`
`void` `setAllowNoSelection(boolean allowNoSelection)` allows to specify whether the dialog prevents returning with no selected elements (default is true).
`void` `setDialogRenderer(ListCellRenderer dialogRenderer)`
`void` `setDialogTitle(String dialogTitle)`
`void` `setEditable(boolean flag)`
`void` `setModel(ComboBoxModel aModel)`
`void` `setModelData(Object... listData)` delegates to the model and adjusts the current selection accordingly
`void` `setSelectedObjects(Object... selection)`
`protected void` `showDialog()`

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, getUI, getUIClassID, hidePopup, insertItemAt, installAncestorListener, intervalAdded, intervalRemoved, isEditable, isLightWeightPopupEnabled, isPopupVisible, paramString, processKeyEvent, removeActionListener, removeAllItems, removeItem, removeItemAt, removeItemListener, removePopupMenuListener, selectedItemChanged, selectWithKeyChar, setAction, setActionCommand, setEditor, setEnabled, setKeySelectionManager, setLightWeightPopupEnabled, setMaximumRowCount, setPopupVisible, setPrototypeDisplayValue, setRenderer, setSelectedIndex, setSelectedItem, setUI, 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, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, 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, 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, transferFocusBackward, 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, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, 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, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Methods inherited from interface com.antelmann.util.Enabled
`isEnabled, setEnabled`

Constructor Detail

### JMultipleSelectionComboBox

    public JMultipleSelectionComboBox(Collection<?> items,
                                      Object... initialSelection)

### JMultipleSelectionComboBox

    public JMultipleSelectionComboBox(Object[] items,
                                      Object... initialSelection)

### JMultipleSelectionComboBox

    public JMultipleSelectionComboBox(String dialogTitle,
                                      Object[] items,
                                      Object... initialSelection)

Method Detail

### createPopupMenu

    protected JPopupMenu createPopupMenu()

### getItems

    public Object[] getItems()

### getDialogRenderer

    public ListCellRenderer getDialogRenderer()

### setDialogRenderer

    public void setDialogRenderer(ListCellRenderer dialogRenderer)

### isAllowNoSelection

    public boolean isAllowNoSelection()

  if false, the dialog prevents returning with no selected elements

  See Also:
    `setAllowNoSelection(boolean)`

### setAllowNoSelection

    public void setAllowNoSelection(boolean allowNoSelection)

  allows to specify whether the dialog prevents returning with no selected elements (default is true). If the noSelectionOption is set, this property is ignored.

  See Also:
    `isAllowNoSelection()`, `insertNoSelectOption()`

### showDialog

    protected void showDialog()

### insertNoSelectOption

    public JMultipleSelectionComboBox insertNoSelectOption()

  puts a special item at the top of the list model that allows to select no entries (if it didn't already exist)

### insertAllSelectOption

    public JMultipleSelectionComboBox insertAllSelectOption()

  puts a special item at the top of the list model that allows to select all entries (if it didn't already exist)

### getContainedElements

    public Object[] getContainedElements(Object... objects)

  returns those objects from the given array that are also elements of this model

### insertSpecialSelectionOption

    public JMultipleSelectionComboBox insertSpecialSelectionOption(String title,
                                                                   Object... selection)
                                                            throws IllegalArgumentException

  puts a special item at the top of the list model that allows to select a given predefined selection by a name

  Throws:
    `IllegalArgumentException`

### containsSpecialSelectionOption

    public boolean containsSpecialSelectionOption(String title)

### removeSpecialSelectionOption

    public boolean removeSpecialSelectionOption(String title)

### removeNoSelectOption

    public boolean removeNoSelectOption()

  removes the 'no selection' option if it existed

### removeAllSelectOption

    public boolean removeAllSelectOption()

  removes the 'select all' option if it existed

### containsNoSelect

    public boolean containsNoSelect()

### containsAllSelect

    public boolean containsAllSelect()

### getDialogTitle

    public String getDialogTitle()

### setDialogTitle

    public void setDialogTitle(String dialogTitle)

### setSelectedObjects

    public void setSelectedObjects(Object... selection)

### getSelectedObjects

    public Object[] getSelectedObjects()

  Specified by:
    `getSelectedObjects` in interface `ItemSelectable`
  Overrides:
    `getSelectedObjects` in class `JComboBox`

### getSelectedItem

    @Deprecated
    public Object getSelectedItem()

  Deprecated. use `getSelectedObjects()` instead

  Overrides:
    `getSelectedItem` in class `JComboBox`

### setModel

    public void setModel(ComboBoxModel aModel)

  Overrides:
    `setModel` in class `JComboBox`

### setEditable

    public void setEditable(boolean flag)

  Overrides:
    `setEditable` in class `JComboBox`

### getModel

    public DefaultComboBoxModel getModel()

  Overrides:
    `getModel` in class `JComboBox`

### setModelData

    public void setModelData(Object... listData)

  delegates to the model and adjusts the current selection accordingly

(c) Holger Antelmann since 2001- all rights reserved (contact: info@antelmann.com)
see www.antelmann.com/developer for further details and available downloads