JIDE 3.5.15

com.jidesoft.combobox
Class MultiSelectListComboBox

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by com.jidesoft.combobox.AbstractComboBox
                  extended by com.jidesoft.combobox.MultiSelectListComboBox
All Implemented Interfaces:
ConverterContextSupport, AlignmentSupport, ActionListener, FocusListener, MouseListener, ImageObserver, ItemSelectable, MenuContainer, Serializable, EventListener, Accessible, PopupMenuListener
Direct Known Subclasses:
CheckBoxListComboBox

public class MultiSelectListComboBox
extends AbstractComboBox

MultiSelectListComboBox is ComboBox which you can choose a value from a drop-down JList which allows multiple selections.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class com.jidesoft.combobox.AbstractComboBox
AbstractComboBox.AccessibleJComboBox, AbstractComboBox.ComboBoxSpinner, AbstractComboBox.ComboBoxTextField, AbstractComboBox.DefaultRendererComponent, AbstractComboBox.DefaultTextFieldEditorComponent, AbstractComboBox.EditorComponent, AbstractComboBox.EnterLazyDelegateAction, AbstractComboBox.LazyDelegateAction, AbstractComboBox.SpinnerEditorComponent
 
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
protected  int _selectionMode
           
protected  int maximumRowCount
          This protected field is implementation specific.
static String PROPERTY_SELECTION_MODE
           
 
Fields inherited from class com.jidesoft.combobox.AbstractComboBox
_dialog, _editable, _editor, _listDataListener, _oldSelectedItemReminder, _popupButton, _popupPanel, _renderer, actionCommand, CLIENT_PROPERTY_HIDE_POPUP_ON_LIST_DATA_CHANGED, CLIENT_PROPERTY_TABLE_CELL_EDITOR, CLIENT_PROPERTY_TABLE_CELL_RENDERER, COMMIT, COMMIT_OR_RESET, COMMIT_OR_REVERT, dataModel, DIALOG, DROPDOWN, HIDE_POPUP_KEY, PERSIST, PROPERTY_SELECTED_ITEM, RESET, REVERT, 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 java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
MultiSelectListComboBox()
           
MultiSelectListComboBox(ComboBoxModel model)
          Creates a new MultiSelectListComboBox.
MultiSelectListComboBox(ComboBoxModel model, Class<?> clazz)
          Creates a new MultiSelectListComboBox.
MultiSelectListComboBox(Object[] objects)
          Creates a new MultiSelectListComboBox.
MultiSelectListComboBox(Object[] objects, Class<?> clazz)
          Creates a new MultiSelectListComboBox.
MultiSelectListComboBox(Vector<?> objects)
          Creates a new MultiSelectListComboBox.
MultiSelectListComboBox(Vector<?> objects, Class<?> clazz)
          Creates a new MultiSelectListComboBox.
 
Method Summary
 Object convertArrayType(Object anObject)
          Converts an array from any component type to the type that can accepted by this combobox.
 AbstractComboBox.EditorComponent createEditorComponent()
          Subclass should implement this method to create the actual editor component.
protected  MultiSelectListChooserPanel createListChooserPanel(ComboBoxModel dataModel, Class<?> clazz, ConverterContext converterContext)
          Creates the MultiSelectListChooserPanel.
 PopupPanel createPopupComponent()
          Subclass should implement this method to create the actual popup component.
protected  JComponent getDelegateTarget()
           
 JList getList()
          Gets the underlying JList.
 int getMaximumRowCount()
          Returns the maximum number of items the combo box can display without a scrollbar.
 int getSelectedIndex()
          Returns the first item in the list that matches the given item.
 int[] getSelectedIndices()
          Returns an array of indices where each integer is the index of the item in the list
 Object getSelectedItem()
          Delegates getSelectedObjects() instead.
 Object[] getSelectedObjects()
          Gets the selected objects.
 int getSelectionMode()
          Returns the current selection mode.
 boolean isUpdateOnChange()
          Checks if the editor area will be updated when the selection is changed in the drop down list.
 void setMaximumRowCount(int count)
          Sets the maximum number of rows the JComboBox displays.
 void setSelectedIndex(int anIndex)
          Selects the item at index anIndex.
 void setSelectedIndices(int[] indices)
          Selects the items at the specified index array.
 void setSelectedItem(Object anObject, boolean fireEvent)
          Sets the selected item.
 void setSelectedObjects(Object[] objects)
          Sets the selected objects.
 void setSelectionMode(int selectionMode)
          Sets the selection mode.
 void setUpdateOnChange(boolean updateOnChange)
          Sets the flag if the editor area will be updated when the selection is changed in the drop down list.
protected  void setupList(JList list)
          Setups the JList for the tree used in the popup panel.
protected  boolean validateValueForNonEditable(Object value)
           
 
Methods inherited from class com.jidesoft.combobox.AbstractComboBox
actionPerformed, addActionListener, addItemListener, addNotify, addPopupMenuListener, calculatePopupLocation, comboBoxSelected, commitEdit, commitEditWithFocusLostBehavior, configurePropertiesFromAction, createActionPropertyChangeListener, createButtonComponent, createDefaultButton, createPopupWindow, createPropertyChangeListener, createSpinner, createTextField, customizeButton, customizeDialog, customizeDialogLocation, customizePopup, delegateKeyStrokes, equals, fireActionEvent, fireItemStateChanged, firePopupMenuCanceled, firePopupMenuWillBecomeInvisible, firePopupMenuWillBecomeVisible, focusGained, focusLost, getAccessibleContext, getAction, getActionCommand, getActionListeners, getBackground, getBaseline, getConverter, getConverterContext, getDefaultCancelAction, getDefaultOKAction, getDelegateKeyStrokes, getDialogCancelAction, getDialogOKAction, getDisabledBackground, getDisabledForeground, getEditor, getFocusLostBehavior, getForeground, getHorizontalAlignment, getItemListeners, getModel, getPopupButton, getPopupCancelBehavior, getPopupLocation, getPopupMenuListeners, getPopupPanel, getPopupType, getPrototypeDisplayValue, getRenderer, getSelectedItemForPopupPanel, getType, getVerticalAlignment, hidePopup, initComponent, initComponent, installColorFontAndBorder, installListener, isButtonOnly, isButtonVisible, isClearSelectionOnListDataChanged, isEditable, isHidePopupOnListDataChanged, isKeepPopupSize, isOpaque, isPopupVisible, isPopupVolatile, isStretchToFit, isToggleValueOnDoubleClick, isUpdateFromPopupOnFly, listDataChanged, modelUpdated, mouseClicked, mouseEntered, mouseExited, mousePressed, mouseReleased, notifyUser, paintComponent, popupMenuCanceled, popupMenuWillBecomeInvisible, popupMenuWillBecomeVisible, processKeyBinding, removeActionListener, removeItemListener, removeNotify, removePopupMenuListener, resetEdit, resetPopup, revertEdit, selectedItemChanged, setAction, setActionCommand, setBackground, setBorder, setButtonOnly, setButtonVisible, setClearSelectionOnListDataChanged, setConverter, setConverterContext, setDisabledBackground, setDisabledForeground, setEditable, setEditor, setEnabled, setFocusLostBehavior, setForeground, setHidePopupOnListDataChanged, setHorizontalAlignment, setKeepPopupSize, setModel, setPopupButton, setPopupCancelBehavior, setPopupType, setPopupVisible, setPopupVolatile, setPrototypeDisplayValue, setRenderer, setSelectedItem, setStretchToFit, setToggleValueOnDoubleClick, setType, setVerticalAlignment, showPopup, showPopupPanel, showPopupPanelAsPopup, undelegateKeyStrokes, uninstallListener, updateToolTipTextForChildren, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, 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, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setFocusTraversalKeys, setFont, 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, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, 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
 

Field Detail

maximumRowCount

protected int maximumRowCount
This protected field is implementation specific. Do not access directly or override. Use the accessor methods instead.

See Also:
getMaximumRowCount(), setMaximumRowCount(int)

_selectionMode

protected int _selectionMode

PROPERTY_SELECTION_MODE

public static final String PROPERTY_SELECTION_MODE
See Also:
Constant Field Values
Constructor Detail

MultiSelectListComboBox

public MultiSelectListComboBox()

MultiSelectListComboBox

public MultiSelectListComboBox(Object[] objects)
Creates a new MultiSelectListComboBox.

Parameters:
objects - the objects

MultiSelectListComboBox

public MultiSelectListComboBox(Vector<?> objects)
Creates a new MultiSelectListComboBox.

Parameters:
objects - the objects

MultiSelectListComboBox

public MultiSelectListComboBox(ComboBoxModel model)
Creates a new MultiSelectListComboBox.

Parameters:
model - the combo box model

MultiSelectListComboBox

public MultiSelectListComboBox(Object[] objects,
                               Class<?> clazz)
Creates a new MultiSelectListComboBox.

Parameters:
objects - the objects
clazz - the class of the data

MultiSelectListComboBox

public MultiSelectListComboBox(Vector<?> objects,
                               Class<?> clazz)
Creates a new MultiSelectListComboBox.

Parameters:
objects - the objects
clazz - the class of the data

MultiSelectListComboBox

public MultiSelectListComboBox(ComboBoxModel model,
                               Class<?> clazz)
Creates a new MultiSelectListComboBox.

Parameters:
model - the combo box model
clazz - the class of the data
Method Detail

createEditorComponent

public AbstractComboBox.EditorComponent createEditorComponent()
Description copied from class: AbstractComboBox
Subclass should implement this method to create the actual editor component.

Specified by:
createEditorComponent in class AbstractComboBox
Returns:
the editor component

createPopupComponent

public PopupPanel createPopupComponent()
Description copied from class: AbstractComboBox
Subclass should implement this method to create the actual popup component.

Specified by:
createPopupComponent in class AbstractComboBox
Returns:
the popup component

createListChooserPanel

protected MultiSelectListChooserPanel createListChooserPanel(ComboBoxModel dataModel,
                                                             Class<?> clazz,
                                                             ConverterContext converterContext)
Creates the MultiSelectListChooserPanel. Subclass can override this method to create its own MultiSelectListChooserPanel. Below is the default implement of this method.

 return new MultiSelectListChooserPanel(dataModel, clazz, converterContext,
         getDefaultOKAction(), getDefaultCancelAction()) {
    protected void setupList(final JList list) {
        super.setupList(list);
        MultiSelectListComboBox.this.setupList(list);
    }
 };
 

Parameters:
dataModel - the combo box model
clazz - the class
converterContext - the converter context
Returns:
CheckBoxListChooserPanel.

setMaximumRowCount

public void setMaximumRowCount(int count)
Sets the maximum number of rows the JComboBox displays. If the number of objects in the model is greater than count, the combo box uses a scrollbar.

Parameters:
count - an integer specifying the maximum number of items to display in the list before using a scrollbar preferred: true description: The maximum number of rows the popup should have

getMaximumRowCount

public int getMaximumRowCount()
Returns the maximum number of items the combo box can display without a scrollbar.

Returns:
an integer specifying the maximum number of items that are displayed in the list before using a scrollbar

setSelectedIndex

public void setSelectedIndex(int anIndex)
Selects the item at index anIndex.

Parameters:
anIndex - an integer specifying the list item to select, where 0 specifies the first item in the list and -1 indicates no selection
Throws:
IllegalArgumentException - if anIndex < -1 or anIndex is greater than or equal to size description: The item at index is selected.

getSelectedIndex

public int getSelectedIndex()
Returns the first item in the list that matches the given item. The result is not always defined if the JComboBox allows selected items that are not in the list. Returns -1 if there is no selected item or if the user specified an item which is not in the list.

Returns:
an integer specifying the currently selected list item, where 0 specifies the first item in the list; or -1 if no item is selected or if the currently selected item is not in the list

setSelectedIndices

public void setSelectedIndices(int[] indices)
Selects the items at the specified index array.

Parameters:
indices - an array of integer specifying the item to select.
Throws:
IllegalArgumentException - if the integer in the array < -1 or is greater than or equal to size

getSelectedIndices

public int[] getSelectedIndices()
Returns an array of indices where each integer is the index of the item in the list

Returns:
an array of selected indices. Please note, there could be value with -1 in the array which means the item is not found in the list.
See Also:
setSelectedIndices(int[])

setSelectedItem

public void setSelectedItem(Object anObject,
                            boolean fireEvent)
Sets the selected item. If the anObject is an array, it will be used directly. Of course, for non-editable MultiSelectListComboBox case, nothing will be selected if any of the element in this array is not in the ComboBoxModel. If the anObject is not an array, we will wrap it in an array and use it.

Overrides:
setSelectedItem in class AbstractComboBox
Parameters:
anObject - the object selected
fireEvent - the flag indicating if an event should be fired

convertArrayType

public Object convertArrayType(Object anObject)
Converts an array from any component type to the type that can accepted by this combobox. If the input is null, null will be returned. If the input is not array, a new array will be created with the first element to be the input value. If the input is an array but not the type it expected, a new array of the type will be created and elements in the input array will be set to the new array, if the type is assignable. If the getType() is null, the input will be returned.

Parameters:
anObject - an array
Returns:
the converted array.

setSelectedObjects

public void setSelectedObjects(Object[] objects)
Sets the selected objects. It actually calls to AbstractComboBox.setSelectedItem(Object) as that method already supports an array. We added this method just to make it clear if user wants to select multiple objects. People tend to think AbstractComboBox.setSelectedItem(Object) will only select one object.

Parameters:
objects - an array of objects you want to select.

getSelectedItem

public Object getSelectedItem()
Delegates getSelectedObjects() instead.

Overrides:
getSelectedItem in class AbstractComboBox
Returns:
the selected objects.
See Also:
AbstractComboBox.setSelectedItem(java.lang.Object)

getSelectedObjects

public Object[] getSelectedObjects()
Gets the selected objects. In the case of CheckBoxListChooserPanel, the selected object is an array of elements that are checked in the MultiSelectListComboBox. This method will always return an array of Objects. You can also use getSelectedItem() method which will return an array of the type you specified in the class parameter of the constructors such as MultiSelectListComboBox(Object[],Class).

Specified by:
getSelectedObjects in interface ItemSelectable
Overrides:
getSelectedObjects in class AbstractComboBox
Returns:
the selected objects.
See Also:
setSelectedObjects(Object[])

getList

public JList getList()
Gets the underlying JList. It will return a not null value only when the list has ever been displayed. If you want to customize the list, it's better to override createListChooserPanel(javax.swing.ComboBoxModel,Class,com.jidesoft.converter.ConverterContext) method and create your own CheckBoxListChooserPanel and JList.

If you want to programmatically set selected index on the list, you can use this method. However do not keep the returned value and use it later because combobox may create a new JList if the popup is volatile.

Please note, this method will show the popup automatically. Otherwise, the JList is not even created.

Returns:
list

getDelegateTarget

protected JComponent getDelegateTarget()
Overrides:
getDelegateTarget in class AbstractComboBox

validateValueForNonEditable

protected boolean validateValueForNonEditable(Object value)
Overrides:
validateValueForNonEditable in class AbstractComboBox

setupList

protected void setupList(JList list)
Setups the JList for the tree used in the popup panel. You can override this method to customize the JList.

Parameters:
list - the list used by ListChooserPanel.

setSelectionMode

public void setSelectionMode(int selectionMode)
Sets the selection mode. The following list describes the accepted selection modes:

Parameters:
selectionMode - the new selection mode.
Throws:
IllegalArgumentException - if the selection mode isn't one of those allowed
See Also:
getSelectionMode()

getSelectionMode

public int getSelectionMode()
Returns the current selection mode.

Returns:
the current selection mode
See Also:
setSelectionMode(int)

isUpdateOnChange

public boolean isUpdateOnChange()
Checks if the editor area will be updated when the selection is changed in the drop down list.

Returns:
true or false.
See Also:
setUpdateOnChange(boolean)

setUpdateOnChange

public void setUpdateOnChange(boolean updateOnChange)
Sets the flag if the editor area will be updated when the selection is changed in the drop down list. If true, the editor area will be updated with the selected items the moment user selects them in the drop down list. It is true by default.

Parameters:
updateOnChange - true or false.

JIDE 3.5.15