JIDE 3.5.15

com.jidesoft.combobox
Class TableExComboBox

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JComboBox
                  extended by com.jidesoft.combobox.ExComboBox
                      extended by com.jidesoft.combobox.TableExComboBox
All Implemented Interfaces:
ConverterContextSupport, ActionListener, ImageObserver, ItemSelectable, MenuContainer, PropertyChangeListener, Serializable, EventListener, Accessible, ListDataListener

public class TableExComboBox
extends ExComboBox

TableComboBox is just like a normal JComboBox which you can choose a value from a drop down table.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class com.jidesoft.combobox.ExComboBox
ExComboBox.LazyDelegateAction
 
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
protected  int _maximumRowCount
          This protected field is implementation specific.
 
Fields inherited from class com.jidesoft.combobox.ExComboBox
CLIENT_PROPERTY_HIDE_POPUP_ON_LIST_DATA_CHANGED, CLIENT_PROPERTY_POPUP_PANEL, CLIENT_PROPERTY_TABLE_CELL_EDITOR, CLIENT_PROPERTY_TABLE_CELL_RENDERER, COMMIT, COMMIT_OR_RESET, COMMIT_OR_REVERT, DIALOG, DOWN_KEY_BEHAVIOR_SELECT_NEXT, DOWN_KEY_BEHAVIOR_SHOW_POPUP, DROPDOWN, PERSIST, PROPERTY_BUTTON_VISIBLE, PROPERTY_SELECTED_ITEM, RESET, REVERT
 
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 java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
TableExComboBox()
          Creates a new TableComboBox.
TableExComboBox(TableModel model)
          Creates a new TableComboBox.
TableExComboBox(TableModel model, Class<?> clazz)
          Creates a new TableComboBox.
TableExComboBox(TableModel model, Class<?> clazz, int type)
          Creates a new TableComboBox.
TableExComboBox(TableModel model, int type)
          Creates a new TableComboBox.
 
Method Summary
 void addItem(Object anObject)
          Adds an item to the item table.
 PopupPanel createPopupComponent()
          Subclass should implement this method to create the actual popup component.
protected  JTable createTable(TableModel model)
          Creates the table.
protected  TableChooserPanel createTableChooserPanel(TableModel dataModel, Class<?> clazz)
          Creates the TableChooserPanel.
 void customizePopup(JidePopup popup, PopupPanel panel)
          Customizes the popup and the popup panel before actually showing them.
 List<KeyStroke> getDelegateKeyStrokes()
          Overrides its super method to remove LEFT/RIGHT/HOME/END key.
protected  JComponent getDelegateTarget(PopupPanel panel)
           
 int getMaximumRowCount()
          Returns the maximum number of items the combo box can display without a scroll bar.
 int getSelectedIndex()
          Returns the first item in the table that matches the given item.
 JTable getTable()
          Gets the underlying JTable.
 TableModel getTableModel()
          Gets the table model used by the table in the popup panel.
 int getValueColumnIndex()
          Returns the value column index.
 void insertItemAt(Object anObject, int index)
          Inserts an item into the item table at a given index.
 boolean isToggleValueOnDoubleClick()
          Checks if double click on the editor part will toggle the value.
 void removeAllItems()
          Removes all items from the item table.
 void removeItem(Object anObject)
          Removes an item from the item table.
 void removeItemAt(int anIndex)
          Removes the item at anIndex This method works only if the TableComboBox uses a mutable data model.
 boolean selectWithKeyChar(char keyChar)
           
 void setMaximumRowCount(int count)
          Sets the maximum number of rows the JComboBox displays.
 void setPopupType(int popupType)
          Sets the popup type.
 void setSelectedIndex(int anIndex)
          Selects the item at index anIndex.
 void setTableModel(TableModel tableModel)
          Sets the table model used by the table in the popup panel.
 void setToggleValueOnDoubleClick(boolean toggleValueOnDoubleClick)
          Sets the flag whether the value will be toggled when double clicking on the editor part.
protected  void setupTable(JTable table)
          Configure the table that is created using createTable(javax.swing.table.TableModel).
 void setValueColumnIndex(int valueColumnIndex)
          Sets the value column index.
 void toggleValue(Component editorComponent, int direction)
           
 
Methods inherited from class com.jidesoft.combobox.ExComboBox
comboBoxSelected, commitEdit, commitEditWithFocusLostBehavior, convertElementToString, convertElementToString, convertStringToElement, convertStringToElement, createButtonComponent, customizeDialog, customizeDialogLocation, customizeRendererComponent, delegateKeyStrokes, equals, fireActionEvent, fireItemStateChanged, getActualUIClassID, getConverter, getConverterContext, getDefaultCancelAction, getDefaultOKAction, getDialogCancelAction, getDialogOKAction, getDownKeyBehavior, getFocusLostBehavior, getPopupCancelBehavior, getPopupLocation, getPopupType, getSelectedItem, getType, getUIComboBoxEditorClassID, getUIComboBoxPopupClassID, getUIComboBoxRendererClassID, initComboBox, installColorFontAndBorder, isButtonOnly, isButtonVisible, isEmptyStringNull, isKeepPopupSize, isPopupVolatile, isReallyFocusLost, isRetrievingValueFromPopup, isStretchToFit, isStretchToFitSet, isUpdateFromPopupOnFly, notifyUser, popupMenuCanceled, processKeyBinding, propertyChange, resetEdit, revertEdit, setButtonOnly, setButtonVisible, setConverter, setConverterContext, setDownKeyBehavior, setEditable, setEmptyStringNull, setFocusLostBehavior, setKeepPopupSize, setModel, setPopupCancelBehavior, setPopupLocation, setPopupVolatile, setSelectedItem, setSelectedItem, setStretchToFit, setType, undelegateKeyStrokes, updateUI, validateValueForNonEditable
 
Methods inherited from class javax.swing.JComboBox
actionPerformed, actionPropertyChanged, addActionListener, addItemListener, addPopupMenuListener, configureEditor, configurePropertiesFromAction, contentsChanged, createActionPropertyChangeListener, createDefaultKeySelectionManager, firePopupMenuCanceled, firePopupMenuWillBecomeInvisible, firePopupMenuWillBecomeVisible, getAccessibleContext, getAction, getActionCommand, getActionListeners, getEditor, getItemAt, getItemCount, getItemListeners, getKeySelectionManager, getModel, getPopupMenuListeners, getPrototypeDisplayValue, getRenderer, getSelectedObjects, getUI, getUIClassID, hidePopup, installAncestorListener, intervalAdded, intervalRemoved, isEditable, isLightWeightPopupEnabled, isPopupVisible, paramString, processKeyEvent, removeActionListener, removeItemListener, removePopupMenuListener, selectedItemChanged, setAction, setActionCommand, setEditor, setEnabled, setKeySelectionManager, setLightWeightPopupEnabled, setPopupVisible, setPrototypeDisplayValue, setRenderer, setUI, showPopup
 
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, 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
 

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)
Constructor Detail

TableExComboBox

public TableExComboBox()
Creates a new TableComboBox.


TableExComboBox

public TableExComboBox(TableModel model)
Creates a new TableComboBox.

Parameters:
model - the table model.

TableExComboBox

public TableExComboBox(TableModel model,
                       Class<?> clazz)
Creates a new TableComboBox.

Parameters:
model - the table model.
clazz - the type of the item set on the combobox.

TableExComboBox

public TableExComboBox(TableModel model,
                       int type)
Creates a new TableComboBox.

Parameters:
model - the table model.
type - the type. It could be DROPDOWN or DIALOG as defined in AbstractComboBox.

TableExComboBox

public TableExComboBox(TableModel model,
                       Class<?> clazz,
                       int type)
Creates a new TableComboBox.

Parameters:
model - the table model.
clazz - the type of the item set on the combobox.
type - the type. It could be DROPDOWN or DIALOG as defined in AbstractComboBox.
Method Detail

customizePopup

public void customizePopup(JidePopup popup,
                           PopupPanel panel)
Description copied from class: ExComboBox
Customizes the popup and the popup panel before actually showing them.

By default, it's an empty implementation.

Overrides:
customizePopup in class ExComboBox
Parameters:
popup - the JidePopup
panel - the popup panel

createPopupComponent

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

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

setPopupType

public void setPopupType(int popupType)
Description copied from class: ExComboBox
Sets the popup type. It could be either DROPDOWN or DIALOG.

Overrides:
setPopupType in class ExComboBox
Parameters:
popupType - the new popup type.

selectWithKeyChar

public boolean selectWithKeyChar(char keyChar)
Overrides:
selectWithKeyChar in class ExComboBox

getDelegateKeyStrokes

public List<KeyStroke> getDelegateKeyStrokes()
Overrides its super method to remove LEFT/RIGHT/HOME/END key.

Overrides:
getDelegateKeyStrokes in class ExComboBox
Returns:
the keystrokes that will be delegated to the table popup.

createTable

protected JTable createTable(TableModel model)
Creates the table. By default, we will return null, meaning the default JTree created by TreeChooserPanel will be used. Subclass can override this method to create a SortableTable or whatever other types of table.

Parameters:
model - the table model.
Returns:
the table.

setupTable

protected void setupTable(JTable table)
Configure the table that is created using createTable(javax.swing.table.TableModel). We had code to setup the table to the way we want. You can subclass it and do future setup but make sure you call super.setupTable(table) first.

Parameters:
table - the table.

createTableChooserPanel

protected TableChooserPanel createTableChooserPanel(TableModel dataModel,
                                                    Class<?> clazz)
Creates the TableChooserPanel. Subclass can override this method to create its own TableChooserPanel.

Parameters:
dataModel - the data model.
clazz - the class.
Returns:
TableChooserPanel.

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 scroll bar.

Overrides:
setMaximumRowCount in class JComboBox
Parameters:
count - an integer specifying the maximum number of items to display in the table before using a scroll bar 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 scroll bar.

Overrides:
getMaximumRowCount in class JComboBox
Returns:
an integer specifying the maximum number of items that are displayed in the table before using a scroll bar.

setSelectedIndex

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

Overrides:
setSelectedIndex in class JComboBox
Parameters:
anIndex - an integer specifying the table item to select, where 0 specifies the first item in the table 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 table that matches the given item. The result is not always defined if the JComboBox allows selected items that are not in the table. Returns -1 if there is no selected item or if the user specified an item which is not in the table.

Overrides:
getSelectedIndex in class JComboBox
Returns:
an integer specifying the currently selected table item, where 0 specifies the first item in the table; or -1 if no item is selected or if the currently selected item is not in the table

getTable

public JTable getTable()
Gets the underlying JTable. It will return a not null value only when the table has ever been displayed. If you want to customize the table, it's better to override createTableChooserPanel(javax.swing.table.TableModel, Class) method and create your own TableChooserPanel and JTable.

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

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

Returns:
table

addItem

public void addItem(Object anObject)
Adds an item to the item table. This method works only if the TableComboBox 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; } };
   }
 

Overrides:
addItem in class JComboBox
Parameters:
anObject - the Object to add to the table
See Also:
MutableComboBoxModel

insertItemAt

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

Overrides:
insertItemAt in class JComboBox
Parameters:
anObject - the Object to add to the table
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 table. This method works only if the TableComboBox uses a mutable data model.

Overrides:
removeItem in class JComboBox
Parameters:
anObject - the object to remove from the item table
See Also:
MutableComboBoxModel

removeItemAt

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

Overrides:
removeItemAt in class JComboBox
Parameters:
anIndex - an int specifying the index of the item to remove, where 0 indicates the first item in the table
See Also:
MutableComboBoxModel

removeAllItems

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

Overrides:
removeAllItems in class JComboBox

setValueColumnIndex

public void setValueColumnIndex(int valueColumnIndex)
Sets the value column index. This value column index will be used to get the value from the table model and be displayed at the editor part of the table combobox.

Parameters:
valueColumnIndex - the new value column index.

getValueColumnIndex

public int getValueColumnIndex()
Returns the value column index. This value column index will be used to get the value from the table model and be displayed at the editor part of the table combobox.

Returns:
value column index.

getTableModel

public TableModel getTableModel()
Gets the table model used by the table in the popup panel.

Returns:
the table model used by the table in the popup panel.

setTableModel

public void setTableModel(TableModel tableModel)
Sets the table model used by the table in the popup panel.

Parameters:
tableModel - the table model

getDelegateTarget

protected JComponent getDelegateTarget(PopupPanel panel)
Overrides:
getDelegateTarget in class ExComboBox

isToggleValueOnDoubleClick

public boolean isToggleValueOnDoubleClick()
Checks if double click on the editor part will toggle the value.

Returns:
true or false.

setToggleValueOnDoubleClick

public void setToggleValueOnDoubleClick(boolean toggleValueOnDoubleClick)
Sets the flag whether the value will be toggled when double clicking on the editor part. By default, it is true.

Parameters:
toggleValueOnDoubleClick - the flag

toggleValue

public void toggleValue(Component editorComponent,
                        int direction)

JIDE 3.5.15