JIDE 3.5.15

com.jidesoft.combobox
Class ListComboBox

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.ListComboBox
All Implemented Interfaces:
ConverterContextSupport, AlignmentSupport, ActionListener, FocusListener, MouseListener, ImageObserver, ItemSelectable, MenuContainer, Serializable, EventListener, Accessible, PopupMenuListener
Direct Known Subclasses:
LegacyEnumCellRenderer

public class ListComboBox
extends AbstractComboBox

ListComboBox is just like a normal JComboBox which you can choose a value from a drop-down list box.

See Also:
Serialized Form

Nested Class Summary
protected  class ListComboBox.ListEditorComponent
           
protected  class ListComboBox.ListRendererComponent
           
 
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 _maximumRowCount
          This protected field is implementation specific.
static Object[] BOOLEAN_ARRAY
          An array of boolean true and false.
 
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
ListComboBox()
           
ListComboBox(ComboBoxModel model)
          Creates a new ListComboBox.
ListComboBox(ComboBoxModel model, Class<?> clazz)
          Creates a new ListComboBox.
ListComboBox(Object[] objects)
          Creates a new ListComboBox.
ListComboBox(Object[] objects, Class<?> clazz)
          Creates a new ListComboBox.
ListComboBox(Vector<?> objects)
          Creates a new ListComboBox.
ListComboBox(Vector<?> objects, Class<?> clazz)
          Creates a new ListComboBox.
 
Method Summary
 void addItem(Object anObject)
          Adds an item to the item list.
 AbstractComboBox.EditorComponent createEditorComponent()
          Subclass should implement this method to create the actual editor component.
protected  JList createList(ComboBoxModel model)
          Creates the list.
protected  ListChooserPanel createListChooserPanel(ComboBoxModel dataModel, Class<?> clazz, ObjectConverter converter, ConverterContext converterContext)
          Creates the ListChooserPanel.
 PopupPanel createPopupComponent()
          Subclass should implement this method to create the actual popup component.
protected  List<KeyStroke> getDelegateKeyStrokes()
          Gets the list of KeyStrokes that will be delegated to the popup panel.
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.
protected  void initComponent(ComboBoxModel model)
          Initialize this component such as creating button, editor etc.
 void insertItemAt(Object anObject, int index)
          Inserts an item into the item list at a given index.
protected  void registerNavigationKeys(AbstractComboBox.EditorComponent editorComponent, JComponent component)
          Register extra key strokes such as UP, DOWN, PAGE UP, PAGE DOWN, CTRL-HOME, CTRL-END on the editor component.
 void removeAllItems()
          Removes all items from the item list.
 void removeItem(Object anObject)
          Removes an item from the item list.
 void removeItemAt(int anIndex)
          Removes the item at anIndex This method works only if the ListComboBox uses a mutable data model.
 void setMaximumRowCount(int count)
          Sets the maximum number of rows the JComboBox displays.
 void setSelectedIndex(int anIndex)
          Selects the item at index anIndex.
protected  void setupList(JList list)
          Setups the JList for the tree used in the popup panel.
 
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, getDialogCancelAction, getDialogOKAction, getDisabledBackground, getDisabledForeground, getEditor, getFocusLostBehavior, getForeground, getHorizontalAlignment, getItemListeners, getModel, getPopupButton, getPopupCancelBehavior, getPopupLocation, getPopupMenuListeners, getPopupPanel, getPopupType, getPrototypeDisplayValue, getRenderer, getSelectedItem, getSelectedItemForPopupPanel, getSelectedObjects, getType, getVerticalAlignment, hidePopup, 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, setSelectedItem, setStretchToFit, setToggleValueOnDoubleClick, setType, setVerticalAlignment, showPopup, showPopupPanel, showPopupPanelAsPopup, undelegateKeyStrokes, uninstallListener, updateToolTipTextForChildren, updateUI, validateValueForNonEditable
 
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)

BOOLEAN_ARRAY

public static Object[] BOOLEAN_ARRAY
An array of boolean true and false.

Constructor Detail

ListComboBox

public ListComboBox()

ListComboBox

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

Parameters:
objects - an array of objects to insert into the combo box

ListComboBox

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

Parameters:
objects - a vector of objects to insert into the combo box

ListComboBox

public ListComboBox(ComboBoxModel model)
Creates a new ListComboBox.

Parameters:
model - a combobox model

ListComboBox

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

Parameters:
objects - an array of objects to insert into the combo box
clazz - the type of the objects in the array.

ListComboBox

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

Parameters:
objects - a vector of objects to insert into the combo box.
clazz - the type of the objects in the vector.

ListComboBox

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

Parameters:
model - a combobox model.
clazz - the type of the objects in the model.
Method Detail

initComponent

protected void initComponent(ComboBoxModel model)
Description copied from class: AbstractComboBox
Initialize this component such as creating button, editor etc. All subclasses must call this method in the constructor to initialize the ComboBox.

Overrides:
initComponent in class AbstractComboBox
Parameters:
model - ComboBoxModel if any. If it's null, use InfiniteComboBoxModel.

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 ListChooserPanel createListChooserPanel(ComboBoxModel dataModel,
                                                  Class<?> clazz,
                                                  ObjectConverter converter,
                                                  ConverterContext converterContext)
Creates the ListChooserPanel. Subclass can override this method to create its own ListChooserPanel. Below is the default implement of this method.

     ListChooserPanel listChooserPanel = new ListChooserPanel(dataModel, clazz, converter, converterContext) {
         protected JList createList(ComboBoxModel model) {
             JList list = ListComboBox.this.createList(model);
             if (list == null) {
                 return super.createList(model);
             }
             return list;
         }
         protected void setupList(final JList list) {
             setHorizontalAlignment(ListComboBox.this.getHorizontalAlignment());
             setVerticalAlignment(ListComboBox.this.getVerticalAlignment());
             super.setupList(list);
             list.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
                 public void valueChanged(ListSelectionEvent e) {
                     if (!e.getValueIsAdjusting() && !Boolean.TRUE.equals(list.getClientProperty(SELECTED_BY_MOUSE_ROLLOVER)))
 {
                         int index = list.getSelectedIndex();
                         if (index != -1) {
                             Object item = dataModel.getElementAt(index);
                             if (getEditor().getItem() != item) {
                                 setSelectedObject(item, false);
                                 getEditor().setItem(item);
                                 getEditor().selectAll();
                             }
                         }
                     }
                 }
             });
             ListComboBox.this.setupList(list);
         }
     };
 

Parameters:
dataModel - the combobox model
clazz - the type of the element
converter - the converter
converterContext - the converter context. Used only when converter is null.
Returns:
ListChooserPanel.

getDelegateKeyStrokes

protected List<KeyStroke> getDelegateKeyStrokes()
Description copied from class: AbstractComboBox
Gets the list of KeyStrokes that will be delegated to the popup panel. By default, we will return ESCAPE, UP, DOWN, PAGE_DOWN, PAGE_UP, ENTER, LEFT, RIGHT, HOME and END keys.

Overrides:
getDelegateKeyStrokes in class AbstractComboBox
Returns:
the list of KeyStrokes that will be delegated to the popup panel.

createList

protected JList createList(ComboBoxModel model)
Creates the list. By default, we will return null, meaning the default JList created by ListChooserPanel will be used. Subclass can override this method to create other types of list.

Parameters:
model - the list model.
Returns:
the list.

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.

registerNavigationKeys

protected void registerNavigationKeys(AbstractComboBox.EditorComponent editorComponent,
                                      JComponent component)
Register extra key strokes such as UP, DOWN, PAGE UP, PAGE DOWN, CTRL-HOME, CTRL-END on the editor component.

Parameters:
editorComponent - the editor component.
component - the text field when the combobox is editable, the renderer component when not editable.

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

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.ObjectConverter,com.jidesoft.converter.ConverterContext) method and create your own ListChooserPanel and JList.

If you want to programatically 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 if the combobox itself is showing (isShowing returns true). Otherwise, it could return null if the popup was never shown before.

Returns:
list

getDelegateTarget

protected JComponent getDelegateTarget()
Overrides:
getDelegateTarget in class AbstractComboBox

addItem

public void addItem(Object anObject)
Adds an item to the item list. This method works only if the ListComboBox uses a mutable data model.

Warning: Focus and keyboard navigation problems may arise if you add duplicate String objects. A workaround is to add new objects instead of String objects and make sure that the toString() method is defined. For example:

   comboBox.addItem(makeObj("Item 1"));
   comboBox.addItem(makeObj("Item 1"));
   ...
   private Object makeObj(final String item)  {
     return new Object() { public String toString() { return item; } };
   }
 

Parameters:
anObject - the Object to add to the list
See Also:
MutableComboBoxModel, insertItemAt(Object, int)

insertItemAt

public void insertItemAt(Object anObject,
                         int index)
Inserts an item into the item list at a given index. This method works only if the ListComboBox uses a mutable data model.

Parameters:
anObject - the Object to add to the list
index - an integer specifying the position at which to add the item
See Also:
MutableComboBoxModel

removeItem

public void removeItem(Object anObject)
Removes an item from the item list. This method works only if the ListComboBox uses a mutable data model.

Parameters:
anObject - the object to remove from the item list
See Also:
MutableComboBoxModel, removeItemAt(int), removeAllItems()

removeItemAt

public void removeItemAt(int anIndex)
Removes the item at anIndex This method works only if the ListComboBox uses a mutable data model.

Parameters:
anIndex - an int specifying the index of the item to remove, where 0 indicates the first item in the list
See Also:
MutableComboBoxModel

removeAllItems

public void removeAllItems()
Removes all items from the item list.


JIDE 3.5.15