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));
changeEvent, listenerList
Constructor and Description |
---|
ComboBoxCellEditor(JComboBox comboBox)
Creates a new ComboBoxCellEditor.
|
Modifier and Type | Method and Description |
---|---|
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.
|
addCellEditorListener, cancelCellEditing, fireEditingCanceled, fireEditingStopped, getCellEditorListeners, isCellEditable, removeCellEditorListener, shouldSelectCell
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addCellEditorListener, cancelCellEditing, isCellEditable, removeCellEditorListener, shouldSelectCell
public ComboBoxCellEditor(JComboBox comboBox)
comboBox
- the comboBox that should be used as the cell editor.public Object getCellEditorValue()
getCellEditorValue
in interface CellEditor
public boolean stopCellEditing()
stopCellEditing
in interface CellEditor
stopCellEditing
in class AbstractCellEditor
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column)
getTableCellEditorComponent
in interface TableCellEditor
table
- the JTable that is asking the editor to edit; can be nullvalue
- the value of the cell to be edited; null is a valid valueisSelected
- will be ignoredrow
- the row of the cell being editedcolumn
- the column of the cell being editedCopyright © 2013. All Rights Reserved.