org.jdesktop.swingx.autocomplete
Class ComboBoxCellEditor

java.lang.Object
  extended by javax.swing.AbstractCellEditor
      extended by org.jdesktop.swingx.autocomplete.ComboBoxCellEditor
All Implemented Interfaces:
Serializable, CellEditor, TableCellEditor

public class ComboBoxCellEditor
extends AbstractCellEditor
implements TableCellEditor, Serializable

This is a cell editor that can be used when a combo box (that has been set up for automatic completion) is to be used in a JTable. The DefaultCellEditor won't work in this case, because each time an item gets selected it stops cell editing and hides the combo box.

Usage example:


 JTable table = ...;
 JComboBox comboBox = ...;
 ...
 TableColumn column = table.getColumnModel().getColumn(0);
 column.setCellEditor(new ComboBoxCellEditor(comboBox));
 

See Also:
Serialized Form

Field Summary
 
Fields inherited from class javax.swing.AbstractCellEditor
changeEvent, listenerList
 
Constructor Summary
ComboBoxCellEditor(JComboBox comboBox)
          Creates a new ComboBoxCellEditor.
 
Method Summary
 Object getCellEditorValue()
          Returns the value contained in the combo box
 Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column)
          Sets an initial value for the combo box.
 boolean stopCellEditing()
          Tells the combo box to stop editing and accept any partially edited value as the value of the combo box.
 
Methods inherited from class javax.swing.AbstractCellEditor
addCellEditorListener, cancelCellEditing, fireEditingCanceled, fireEditingStopped, getCellEditorListeners, isCellEditable, removeCellEditorListener, shouldSelectCell
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.swing.CellEditor
addCellEditorListener, cancelCellEditing, isCellEditable, removeCellEditorListener, shouldSelectCell
 

Constructor Detail

ComboBoxCellEditor

public ComboBoxCellEditor(JComboBox comboBox)
Creates a new ComboBoxCellEditor.

Parameters:
comboBox - the comboBox that should be used as the cell editor.
Method Detail

getCellEditorValue

public Object getCellEditorValue()
Returns the value contained in the combo box

Specified by:
getCellEditorValue in interface CellEditor
Returns:
the value contained in the combo box

stopCellEditing

public boolean stopCellEditing()
Tells the combo box to stop editing and accept any partially edited value as the value of the combo box. Always returns true.

Specified by:
stopCellEditing in interface CellEditor
Overrides:
stopCellEditing in class AbstractCellEditor
Returns:
true

getTableCellEditorComponent

public Component getTableCellEditorComponent(JTable table,
                                             Object value,
                                             boolean isSelected,
                                             int row,
                                             int column)
Sets an initial value for the combo box. Returns the combo box that should be added to the client's Component hierarchy. Once installed in the client's hierarchy this combo box will then be able to draw and receive user input.

Specified by:
getTableCellEditorComponent in interface TableCellEditor
Parameters:
table - the JTable that is asking the editor to edit; can be null
value - the value of the cell to be edited; null is a valid value
isSelected - will be ignored
row - the row of the cell being edited
column - the column of the cell being edited
Returns:
the combo box for editing